Skip to content

export

export ¤

Feature matrix export utilities for ts-shape.

Converts long-format timeseries DataFrames into wide feature matrices suitable for machine-learning workflows.

FeatureMatrixExporter ¤

Convert long-format timeseries DataFrames to wide feature matrices.

Pivots a multiplexed DataFrame (one row per timestamp per signal) into a single row per entity (e.g. cycle, segment, batch) with one column per {uuid}__{value_column}__{agg} combination. The result is ready for use with scikit-learn, XGBoost, or any tabular ML framework.

Usage::

from ts_shape.features.export import FeatureMatrixExporter

# Long-format df: columns systime, uuid, value_double
matrix = FeatureMatrixExporter.to_feature_matrix(df, uuid_column='uuid', value_columns=['value_double'])

to_feature_matrix classmethod ¤

to_feature_matrix(
    dataframe: DataFrame,
    uuid_column: str = "uuid",
    value_columns: list[str] | None = None,
    agg_funcs: dict[str, str | Callable] | None = None,
    group_column: str | None = None,
) -> pd.DataFrame

Pivot a long-format DataFrame into a wide feature matrix.

Parameters:

Name Type Description Default
dataframe DataFrame

Long-format DataFrame containing signal data.

required
uuid_column str

Column whose unique values become column prefixes (e.g. 'uuid').

'uuid'
value_columns list[str] | None

Numeric columns to aggregate. If None, the numeric value_* columns (value_double, value_integer) are used; flags such as is_delta are not features.

None
agg_funcs dict[str, str | Callable] | None

Mapping of name -> callable or pandas agg string. Defaults to mean, std (sample standard deviation, ddof=1), min, max.

None
group_column str | None

Optional column to use as the row index of the output matrix (e.g. 'cycle_uuid', 'batch_id'). When None the entire DataFrame is treated as one group and a single-row matrix is returned.

None

Returns:

Type Description
DataFrame

Wide-format DataFrame. Columns are named

DataFrame

{uuid}__{value_column}__{agg}. Row index is group_column

DataFrame

when provided, otherwise 0.

Raises:

Type Description
ColumnNotFoundError

If uuid_column, a value_columns entry or group_column is not in dataframe.

ValueError

If no numeric value column is found.