Skip to main content

kats: kit to analyze time series

Project description

Description

Kats is a toolkit to analyze time series data, a lightweight, easy-to-use, and generalizable framework to perform time series analysis. Time series analysis is an essential component of Data Science and Engineering work at industry, from understanding the key statistics and characteristics, detecting regressions and anomalies, to forecasting future trends. Kats aims to provide the one-stop shop for time series analysis, including detection, forecasting, feature extraction/embedding, multivariate analysis, etc.

Kats is released by Facebook's Infrastructure Data Science team. It is available for download on PyPI.

Important links

Installation in Python

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

pip install --upgrade pip
pip install kats

If you need only a small subset of Kats, you can install a minimal version of Kats with

MINIMAL_KATS=1 pip install kats

which omits many dependencies (everything in test_requirements.txt). However, this will disable many functionalities and cause import kats to log warnings. See setup.py for full details and options.

Examples

Here are a few sample snippets from a subset of Kats offerings:

Forecasting

Using Prophet model to forecast the air_passengers data set.

import pandas as pd

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",
    header=0,
    names=["time", "passengers"],
)

# convert to TimeSeriesData object
air_passengers_ts = TimeSeriesData(air_passengers_df)

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

# 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

Using CUSUM detection algorithm on simulated data set.

# import packages
import numpy as np
import pandas as pd

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()

TSFeatures

We can extract meaningful features from the given time series data

# Initiate feature extraction class
import pandas as pd
from kats.consts import TimeSeriesData
from kats.tsfeatures.tsfeatures import TsFeatures

# take `air_passengers` data as an example
air_passengers_df = pd.read_csv(
    "../kats/data/air_passengers.csv",
    header=0,
    names=["time", "passengers"],
)

# convert to TimeSeriesData object
air_passengers_ts = TimeSeriesData(air_passengers_df)

# calculate the TsFeatures
features = TsFeatures().transform(air_passengers_ts)

Changelog

Version 0.2.0

  • Forecasting
    • Added global model, a neural network forecasting model
    • Added global model tutorial
    • Consolidated backtesting APIs and some minor bug fixes
  • Detection
    • Added model optimizer for anomaly/ changepoint detection
    • Added evaluators for anomaly/changepoint detection
    • Improved simulators, to build synthetic data and inject anomalies
    • Added new detectors: ProphetTrendDetector, Dynamic Time Warping based detectors
    • Support for meta-learning, to recommend anomaly detection algorithms and parameters for your dataset
    • Standardized API for some of our legacy detectors: OutlierDetector, MKDetector
    • Support for Seasonality Removal in StatSigDetector
  • TsFeatures
    • Added time-based features
  • Others
    • Bug fixes, code coverage improvement, etc.

Version 0.1.0

  • Initial release

Contributors

Kats is a project with several skillful researchers and engineers contributing to it.

Kats is currently maintained by Xiaodong Jiang with major contributions coming from many talented individuals in various forms and means. A non-exhaustive but growing list needs to mention: Sudeep Srivastava, Sourav Chatterjee, Jeff Handler, Rohan Bopardikar, Dawei Li, Yanjun Lin, Yang Yu, Michael Brundage, Caner Komurlu, Rakshita Nagalla, Zhichao Wang, Hechao Sun, Peng Gao, Wei Cheung, Jun Gao, Qi Wang, Morteza Kazemi, Tihamér Levendovszky, Jian Zhang, Ahmet Koylan, Kun Jiang, Aida Shoydokova, Ploy Temiyasathit, Sean Lee, Nikolay Pavlovich Laptev, Peiyi Zhang, Emre Yurtbay, Daniel Dequech, Rui Yan, William Luo, Marius Guerard, and Pietari Pulkkinen.

License

Kats is licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kats-0.2.0.tar.gz (2.9 MB view details)

Uploaded Source

Built Distribution

kats-0.2.0-py3-none-any.whl (612.5 kB view details)

Uploaded Python 3

File details

Details for the file kats-0.2.0.tar.gz.

File metadata

  • Download URL: kats-0.2.0.tar.gz
  • Upload date:
  • Size: 2.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.8

File hashes

Hashes for kats-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bab55112f26d6458dd444696dfe9fd42097effac03813bcef700d87be361149d
MD5 eed3abbed4bac052c85ea72964d745b7
BLAKE2b-256 6863f5e85aff48eefa196b0cb9e21debedf451e842925b12fb5b724f765ca249

See more details on using hashes here.

File details

Details for the file kats-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: kats-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 612.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.8

File hashes

Hashes for kats-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12fb05122103eedf679bdcebe6daaa6d7ac91ef4c0d3eb062e912006f7a22db7
MD5 8c68b02255eabc39cb5e6b15f68f43e2
BLAKE2b-256 4839c69186c8faee6b5d6964ce63188f80f62a5c420f5a06811504e915d18d1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page