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'
|
value_cols
|
Optional[List[str]]
|
Numeric columns to aggregate. If |
None
|
agg_funcs
|
Optional[Dict[str, Union[str, Callable]]]
|
Mapping of |
None
|
group_col
|
Optional[str]
|
Optional column to use as the row index of the output
matrix (e.g. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Wide-format DataFrame. Columns are named |
DataFrame
|
|
DataFrame
|
when provided, otherwise 0. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |