Kats: Meta's Time Series Toolkit for Detection, Forecasting, and Feature Extraction

February 17, 2025

|repo-review

by Florian Narr

Kats: Meta's Time Series Toolkit for Detection, Forecasting, and Feature Extraction

What it does

Kats is a Python library for time series analysis — detection, forecasting, feature extraction, and multivariate analysis — all built around a single TimeSeriesData wrapper. It came out of Meta's Infrastructure Data Science team and is the toolkit they used internally to monitor production systems at scale.

Why I starred it

Most time series libraries specialize. statsmodels is your stats Swiss Army knife. Prophet is for forecasting with seasonality. Isolation Forest for anomalies. You end up stitching them together yourself. Kats bundles all of it: 10+ forecasting models, a dozen detectors, a feature extractor that produces 40+ statistics from a time series, and a meta-learning layer that picks the right model for your data automatically.

What pushed me to star it is the meta-learning angle. There's a metalearner module (kats/models/metalearner/) that uses features extracted by TsFeatures to recommend which forecasting model — Prophet, ARIMA, Holt-Winters, LSTM — will perform best on a given series, without manual tuning. The underlying paper was presented at the International Symposium on Forecasting. Running feature extraction as the input to model selection is the kind of thing you build yourself after enough production pain, and here it's already wired up.

How it works

The core abstraction is TimeSeriesData in kats/consts.py. Everything — detectors, models, feature extractors — takes one. It wraps a DataFrame with a time column and one or more value columns, validates granularity, supports univariate and multivariate cases, and handles interpolation. The error hierarchy is explicit: DataError, DataIrregularGranularityError, DataInsufficientError, ParameterError — all subclasses of KatsError. Granularity validation happens at construction time when you pass validate_frequency=True.

The detection framework is in kats/detectors/. The base Detector class in detector.py is abstract; every detector inherits from it. The DetectorModelRegistry in the same file is a metaclass that auto-registers every non-abstract subclass by name — so you can do DetectorModelRegistry.get_detector_model_by_name("CUSUMDetector") and get the class back without a manual registry.

CUSUM is the workhorse detector. The implementation in kats/detectors/cusum_detection.py does two things: first, it locates the change point by iteratively estimating means before and after the midpoint until convergence (capped by max_iter, default 10); then it conducts a log-likelihood ratio test against a null hypothesis of no change. The result is a CUSUMChangePoint — a subclass of TimeSeriesChangePoint — that carries mu0, mu1, delta, llr, p_value, direction, and a stable_changepoint flag indicating whether the iterative location step converged. The detector also supports vectorized CUSUM via VectorizedCUSUMChangePointVal for batch evaluation across many series.

The feature extractor in kats/tsfeatures/tsfeatures.py is the most technically interesting piece. It conditionally imports numba and applies @jit to speed-critical paths. If numba isn't available, it falls back to a no-op decorator that returns the function unchanged — the fallback is a clean four-line pattern that handles optional JIT compilation without changing calling code. The features cover ACF/PACF, STL decomposition, KPSS stationarity tests, ARCH tests for heteroskedasticity, BOCPD changepoint features, and outlier statistics. They're configured via a _ALL_TS_FEATURES list of (method_name, params) tuples that drives which get_* methods run, parameterized by instance attributes. You can disable feature groups individually.

Forecasting models all inherit from Model in kats/models/model.py, a generic base typed on the params class: Model[ParamsType]. Every model exposes fit(), predict(), and plot(). The models directory includes Prophet, ARIMA, SARIMA, LSTM, NeuralProphet, Holt-Winters, Theta, VAR, and a global neural network model — plus an ensemble sub-package.

Using it

pip install kats

CUSUM change point detection on a simulated shift:

import numpy as np
import pandas as pd
from kats.consts import TimeSeriesData
from kats.detectors.cusum_detection import CUSUMDetector

df = pd.DataFrame({
    "time": pd.date_range("2024-01-01", periods=60, freq="D"),
    "value": np.concatenate([
        np.random.normal(1.0, 0.2, 30),
        np.random.normal(2.5, 0.2, 30),  # step change at index 30
    ]),
})
ts = TimeSeriesData(df)
cps = CUSUMDetector(ts).detector()
# Returns list of CUSUMChangePoint  each has .start_time, .delta, .p_value, .direction
print(cps[0])
# CUSUMChangePoint(start_time: 2024-01-31, ..., delta: 1.47, p_value: 0.0, direction: increase)

Feature extraction for downstream ML:

from kats.tsfeatures.tsfeatures import TsFeatures

features = TsFeatures().transform(ts)
# Returns dict of 40+ features: stl_trend, acf_1, kpss_stat, num_outliers, etc.

Meta-learning model selection:

from kats.models.metalearner.metalearner_hpt import MetaLearnHPT

# Trained on synthetic series  recommends hyperparameters for your model of choice
hpt = MetaLearnHPT(Prophet)
hpt.build_model()
params = hpt.pred_params(ts)

Rough edges

The library is still alive — last commit was March 2026, fixing type errors for a Python 3.14 compatibility upgrade — but the velocity is low and mostly maintenance. Version 0.2.0 was released in early 2022; there's no 0.3.0 on the horizon.

The dependency footprint is large. Full installation pulls Prophet, NeuralProphet, statsmodels, torch, numba, llvmlite, and more. MINIMAL_KATS=1 pip install kats omits most of these, but then many modules raise import warnings and silently skip functionality.

The plotting methods exist (detector.plot(), model.plot()) but documentation is inconsistent. Several tutorial notebooks in tutorials/ reference data paths (../kats/data/air_passengers.csv) that only work when run from the repo root, not when installed via pip.

The tests in kats/tests/ are real unit tests — not notebooks — which is good. Coverage is uneven though: the meta-learner tests are thin relative to the complexity of the feature-to-model mapping logic, and the multivariate detectors have sparse coverage.

Bottom line

If you're monitoring production systems with irregular time series and need change point detection, anomaly alerting, and forecasting without assembling five separate libraries, Kats is worth pulling in. The meta-learning layer is genuinely useful for large-scale monitoring where you can't hand-tune a model per series.

facebookresearch/Kats on GitHub
facebookresearch/Kats