Contents

Time Series Analysis Framework

A lightweight, easy-to-use, extendable framework kit to analyze time series data

Kats Logo

Time Series Analysis

Time series analysis is a fundamental domain in data science and machine learning, with massive applications in various sectors such as e-commerce, finance, capacity planning, supply chain management, medicine, weather, energy, astronomy, and many others.

Kats is a one-stop shop

Kats is a lightweight, easy-to-use, and generalizable framework for generic time series analysis, including forecasting, anomaly detection, multivariate analysis, and feature extraction/embedding.

Kats is the first comprehensive Python library for generic time series analysis, which provides both classical and advanced techniques to model time series data.

Kats connects various domains in time series analysis, where the users can explore the basic characteristics of their time series data, predict the future values, monitor the anomalies, and incorporate them into their ML models and pipelines.

What it does

Kats provides a set of algorithms and models for four domains in time series analysis: forecasting, detection, feature extraction and embedding, and multivariate analysis.

  • Forecasting: Kats provides a full set of tools for forecasting that includes 10+ individual forecasting models, ensembling, a self-supervised learning (meta-learning) model, backtesting, hyperparameter tuning, and empirical prediction intervals.

  • Detection: Kats supports functionalities to detect various patterns on time series data, including seasonalities, outlier, change point, and slow trend changes.

  • Feature extraction and embedding: The time series feature (TSFeature) extraction module in Kats can produce 65 features with clear statistical definitions, which can be incorporated in most machine learning (ML) models, such as classification and regression.

  • Useful utilities: Kats also provides a set of useful utilities, such as time series simulators.

Installation in Python

Kats is on PyPI, so you can use pip to install it.

1
2
pip install --upgrade pip
pip install kats

Forecasting Example

Using Prophet model to forecast the air_passengers data set.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from kats.consts import TimeSeriesData
from kats.models.prophet import ProphetModel, ProphetParams

# take `air_passengers` data as an example
air_passengers_df = pd.read_csv("../kats/data/air_passengers.csv")

# convert to TimeSeriesData object
air_passengers_ts = TimeSeriesData(air_passengers_df)

# create a model param instance
# note that additive mode gives worse results
params = ProphetParams(seasonality_mode='multiplicative')

# create a prophet model instance
m = ProphetModel(air_passengers_ts, params)

# fit model simply by calling m.fit()
m.fit()

# make prediction for next 30 month
fcst = m.predict(steps=30, freq="MS")

Detection Example

Using CUSUM detection algorithm on simulated data set.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from kats.consts import TimeSeriesData
from kats.detectors.cusum_detection import CUSUMDetector

# simulate time series with increase
np.random.seed(10)
df_increase = pd.DataFrame(
    {
        'time': pd.date_range('2019-01-01', '2019-03-01'),
        'increase':np.concatenate([np.random.normal(1,0.2,30), np.random.normal(2,0.2,30)]),
    }
)

# convert to TimeSeriesData object
timeseries = TimeSeriesData(df_increase)

# run detector and find change points
change_points = CUSUMDetector(timeseries).detector()