Kats Aggregation
Use this skill after the time-series data-prep step. Kats TsFeatures is best for legacy or existing Kats projects that need interpretable statistical time-series features as tabular inputs for downstream classification, regression, clustering, anomaly workflows, meta-learning, or exploratory profiling.
Do not treat TsFeatures as a forecaster, classifier, clusterer, or supervised feature selector. It transforms TimeSeriesData into feature dictionaries; downstream modeling is separate.
Minimum Install
python -m pip install --upgrade pip
python -m pip install kats
MINIMAL_KATS=1 python -m pip install kats
MINIMAL_KATS=1 omits many dependencies and disables functionality. Kats 0.2.0 on PyPI is alpha-era software released in 2022 and declares Python 3.7/3.8 classifiers; check environment compatibility before promising execution.
Data Contract
- Require a prepared contract: series/entity id, sorted timestamp column, numeric value column(s), train/validation/test split, window policy, target alignment if downstream supervised learning is used, and leakage notes.
- Convert each series to
kats.consts.TimeSeriesData. Initialize from a pandas DataFrame, Series, or DatetimeIndex plus value data.
- Use the default
time column or pass time_col_name; values can be a pandas Series for univariate data or a DataFrame for multivariate data.
TsFeatures().transform(ts) returns {feature: value} for univariate input and list[dict] for multivariate input.
- Kats does not document one panel/long container for many independent series. Loop over ids and build one feature row per id/window.
- Source code raises
ValueError for series shorter than 5 points; some feature groups require longer windows or seasonal periods.
Read references/kats-tsfeatures-data.md before adapting univariate, multivariate, multiple-series, or rolling-window data.
Extraction Pattern
import pandas as pd
from kats.consts import TimeSeriesData
from kats.tsfeatures.tsfeatures import TsFeatures
ts = TimeSeriesData(df[["time", "value"]], time_col_name="time")
features = TsFeatures().transform(ts)
row = {"series_id": series_id, **features}
For multiple independent series:
rows = []
for series_id, group in train_df.groupby("series_id", sort=False):
ts = TimeSeriesData(group[["time", "value"]], time_col_name="time")
rows.append({"series_id": series_id, **TsFeatures().transform(ts)})
X_features = pd.DataFrame.from_records(rows).set_index("series_id")
For multivariate TimeSeriesData, handle the documented list[dict] output explicitly and name rows by component/column.
Feature Configuration
- Default feature groups in current source include
statistics, stl_features, level_shift_features, acfpacf_features, special_ac, holt_params, and hw_params.
- Optional groups default off in source:
cusum_detector, robust_stat_detector, bocp_detector, outlier_detector, trend_detector, nowcasting, seasonalities, and time.
- Use
selected_features=[...] to opt into named features or feature groups.
- Use keyword switches such as
stl_features=False or time=True to opt out/in documented groups.
- Official docs/pages disagree on fixed feature counts; use group/feature names from the installed version.
Read references/kats-tsfeatures-api-map.md before selecting groups, parameters, or feature names.
Validation and Metrics
- Validate the feature extraction plus downstream model with the split strategy required by the task: temporal splits for forecasting-like labels, group-aware splits for entity leakage, and stratified splits for imbalanced classification labels.
- For classification, report F1-macro, balanced accuracy, ROC-AUC/PR-AUC where probabilities exist, and confusion matrices.
- For regression, report MAE/RMSE plus scale-aware metrics when useful.
- For clustering, evaluate feature scaling, cluster stability, silhouette/task-specific metrics, and feature distribution sanity checks.
- Use
TimeSeriesData.plot(cols=[...]) or pandas/matplotlib to inspect raw series and windows; Kats does not document a dedicated TsFeatures plotting API.
Anti-Leakage Rules
- Split ids, entities, windows, or temporal periods before imputing, scaling, PCA, feature selection, or fitting downstream models.
- Extract features separately inside each train fold when feature windows are derived from longer chronological series.
- Rolling/windowed feature rows must use only observations available at the row's decision timestamp.
- If feature group/parameter choices are selected from labels or validation metrics, select them inside train/validation folds only.
- Fit
StandardScaler, PCA, supervised selectors, classifiers, regressors, and cluster postprocessing only on train folds.
- Keep timestamp cutoff, window length, seasonal period, frequency, entity id, and target alignment explicit in the data-prep contract.
Common Errors
- Expecting a DataFrame output;
TsFeatures.transform() returns a dict or list of dicts.
- Passing many independent series as one multivariate
TimeSeriesData when one row per entity is required.
- Using series shorter than 5 points or too short for
window_size, stl_period, nbins, or lag-based features.
- Assuming documented supervised feature selection or sklearn transformers exist in Kats TSFeatures; they are not documented.
- Forgetting optional detector, nowcasting, seasonality, and time groups are off by default in current source.
- Scaling/PCA on all feature rows before splitting.
- Relying on one fixed TSFeatures count despite official count inconsistencies across homepage, tutorial, and source.
References
- Read
references/kats-tsfeatures-data.md for TimeSeriesData contracts and tabular-row construction.
- Read
references/kats-tsfeatures-api-map.md for feature groups, parameters, defaults, and documented gaps.
- Read
references/official-sources.md for official sources consulted.
- Use
scripts/validate_kats_tsfeatures_csv.py to sanity-check single-series or panel CSVs before creating TimeSeriesData.
Ready Checklist
- Data-prep contract defines id, time, value columns, windows, split strategy, and leakage risks.
- Each feature row maps to one entity/component/window with no future observations.
- Kats/Python/dependency compatibility is checked for the target environment.
- Feature groups and parameters are documented from installed Kats source/docs.
- Scaling, PCA, selection, and downstream modeling are fit only on train folds.
- Metrics and plots are computed on held-out or validation data appropriate to the downstream task.
1---2name: aggregation-kats3description: Use Facebook/Meta Kats TSFeatures for time-series aggregation and feature extraction after validating data, including TimeSeriesData inputs, univariate and multivariate feature dictionaries, multiple independent series loops, feature groups, opt-in/opt-out feature selection, tabular ML matrices, plotting context, and leakage-safe train/fold feature generation.4---56# Kats Aggregation78Use this skill after the time-series data-prep step. Kats `TsFeatures` is best for legacy or existing Kats projects that need interpretable statistical time-series features as tabular inputs for downstream classification, regression, clustering, anomaly workflows, meta-learning, or exploratory profiling.910Do not treat `TsFeatures` as a forecaster, classifier, clusterer, or supervised feature selector. It transforms `TimeSeriesData` into feature dictionaries; downstream modeling is separate.1112## Minimum Install1314```bash15python -m pip install --upgrade pip16python -m pip install kats17MINIMAL_KATS=1 python -m pip install kats18```1920`MINIMAL_KATS=1` omits many dependencies and disables functionality. Kats 0.2.0 on PyPI is alpha-era software released in 2022 and declares Python 3.7/3.8 classifiers; check environment compatibility before promising execution.2122## Data Contract2324- Require a prepared contract: series/entity id, sorted timestamp column, numeric value column(s), train/validation/test split, window policy, target alignment if downstream supervised learning is used, and leakage notes.25- Convert each series to `kats.consts.TimeSeriesData`. Initialize from a pandas `DataFrame`, `Series`, or `DatetimeIndex` plus value data.26- Use the default `time` column or pass `time_col_name`; values can be a pandas `Series` for univariate data or a `DataFrame` for multivariate data.27- `TsFeatures().transform(ts)` returns `{feature: value}` for univariate input and `list[dict]` for multivariate input.28- Kats does not document one panel/long container for many independent series. Loop over ids and build one feature row per id/window.29- Source code raises `ValueError` for series shorter than 5 points; some feature groups require longer windows or seasonal periods.3031Read `references/kats-tsfeatures-data.md` before adapting univariate, multivariate, multiple-series, or rolling-window data.3233## Extraction Pattern3435```python36import pandas as pd37from kats.consts import TimeSeriesData38from kats.tsfeatures.tsfeatures import TsFeatures3940ts = TimeSeriesData(df[["time", "value"]], time_col_name="time")41features = TsFeatures().transform(ts)4243row = {"series_id": series_id, **features}44```4546For multiple independent series:4748```python49rows = []50for series_id, group in train_df.groupby("series_id", sort=False):51 ts = TimeSeriesData(group[["time", "value"]], time_col_name="time")52 rows.append({"series_id": series_id, **TsFeatures().transform(ts)})5354X_features = pd.DataFrame.from_records(rows).set_index("series_id")55```5657For multivariate `TimeSeriesData`, handle the documented `list[dict]` output explicitly and name rows by component/column.5859## Feature Configuration6061- Default feature groups in current source include `statistics`, `stl_features`, `level_shift_features`, `acfpacf_features`, `special_ac`, `holt_params`, and `hw_params`.62- Optional groups default off in source: `cusum_detector`, `robust_stat_detector`, `bocp_detector`, `outlier_detector`, `trend_detector`, `nowcasting`, `seasonalities`, and `time`.63- Use `selected_features=[...]` to opt into named features or feature groups.64- Use keyword switches such as `stl_features=False` or `time=True` to opt out/in documented groups.65- Official docs/pages disagree on fixed feature counts; use group/feature names from the installed version.6667Read `references/kats-tsfeatures-api-map.md` before selecting groups, parameters, or feature names.6869## Validation and Metrics7071- Validate the feature extraction plus downstream model with the split strategy required by the task: temporal splits for forecasting-like labels, group-aware splits for entity leakage, and stratified splits for imbalanced classification labels.72- For classification, report F1-macro, balanced accuracy, ROC-AUC/PR-AUC where probabilities exist, and confusion matrices.73- For regression, report MAE/RMSE plus scale-aware metrics when useful.74- For clustering, evaluate feature scaling, cluster stability, silhouette/task-specific metrics, and feature distribution sanity checks.75- Use `TimeSeriesData.plot(cols=[...])` or pandas/matplotlib to inspect raw series and windows; Kats does not document a dedicated `TsFeatures` plotting API.7677## Anti-Leakage Rules7879- Split ids, entities, windows, or temporal periods before imputing, scaling, PCA, feature selection, or fitting downstream models.80- Extract features separately inside each train fold when feature windows are derived from longer chronological series.81- Rolling/windowed feature rows must use only observations available at the row's decision timestamp.82- If feature group/parameter choices are selected from labels or validation metrics, select them inside train/validation folds only.83- Fit `StandardScaler`, PCA, supervised selectors, classifiers, regressors, and cluster postprocessing only on train folds.84- Keep timestamp cutoff, window length, seasonal period, frequency, entity id, and target alignment explicit in the data-prep contract.8586## Common Errors8788- Expecting a DataFrame output; `TsFeatures.transform()` returns a dict or list of dicts.89- Passing many independent series as one multivariate `TimeSeriesData` when one row per entity is required.90- Using series shorter than 5 points or too short for `window_size`, `stl_period`, `nbins`, or lag-based features.91- Assuming documented supervised feature selection or sklearn transformers exist in Kats TSFeatures; they are not documented.92- Forgetting optional detector, nowcasting, seasonality, and time groups are off by default in current source.93- Scaling/PCA on all feature rows before splitting.94- Relying on one fixed TSFeatures count despite official count inconsistencies across homepage, tutorial, and source.9596## References9798- Read `references/kats-tsfeatures-data.md` for `TimeSeriesData` contracts and tabular-row construction.99- Read `references/kats-tsfeatures-api-map.md` for feature groups, parameters, defaults, and documented gaps.100- Read `references/official-sources.md` for official sources consulted.101- Use `scripts/validate_kats_tsfeatures_csv.py` to sanity-check single-series or panel CSVs before creating `TimeSeriesData`.102103## Ready Checklist104105- Data-prep contract defines id, time, value columns, windows, split strategy, and leakage risks.106- Each feature row maps to one entity/component/window with no future observations.107- Kats/Python/dependency compatibility is checked for the target environment.108- Feature groups and parameters are documented from installed Kats source/docs.109- Scaling, PCA, selection, and downstream modeling are fit only on train folds.110- Metrics and plots are computed on held-out or validation data appropriate to the downstream task.