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_col}__{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_col='uuid', value_cols=['value_double'])

to_feature_matrix classmethod ¤

to_feature_matrix(
    df: DataFrame,
    uuid_col: str = "uuid",
    value_cols: Optional[List[str]] = None,
    agg_funcs: Optional[
        Dict[str, Union[str, Callable]]
    ] = None,
    group_col: Optional[str] = None,
) -> pd.DataFrame

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

Parameters:

Name Type Description Default
df DataFrame

Long-format DataFrame containing signal data.

required
uuid_col str

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

'uuid'
value_cols Optional[List[str]]

Numeric columns to aggregate. If None, all numeric columns except uuid_col are used.

None
agg_funcs Optional[Dict[str, Union[str, Callable]]]

Mapping of name -> callable or pandas agg string. Defaults to mean, std, min, max.

None
group_col Optional[str]

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_col}__{agg}. Row index is group_col

DataFrame

when provided, otherwise 0.

Raises:

Type Description
ValueError

If uuid_col is not in df.