• API

›Detection

Forecasting

  • Autoregressive Neural Network (AR_net)
  • Quadratic Model
  • Linear Model
  • KatsEnsemble
  • Empirical Confidence Interval
  • STLF
  • Theta
  • Holt-Winter’s
  • Prophet
  • SARIMA
  • ARIMA

Detection

  • BOCPD: Residual Translation
  • BOCPD: Bayesian Online Changepoint Detection
  • Outlier Detection
  • ACFDetector
  • Seasonality Detector
  • Cusum Detector

TSFeatures

  • TsFeatures

Multivariate

  • Multivariate Outlier Detection
  • VAR

Utilities

  • Model Hyperparameter Tuning
  • Backtesting
  • Time Series Decomposition
  • Dataswarm Operators

Outlier Detection

Outliers in Time Series can cause a lot of issues in downstream processing. Therefore removing outliers is important in any time series analysis. In Kats we have implemented an outlier detection algorithm which mimics the outlier detection algorithm in R. The steps are outlined as follows :

  • We do a time series decomposition of the input time series with additive or multiplicative decomposition as specified
  • We generate a residual time series by either removing only trend or both trend and seasonality based on the strength of the seasonality in the time series.
  • We detect points in the residual which are outside 3 times the inter quartile range. We can tune the outlier detection to incorporate less or more outliers by tuning this parameter

API

class OutlierDetector(
        data: TimeSeriesData,
        decomp: str = 'additive',
        iqr_mult: float = 3.0)

Parameters:

data: TimeSeriesData object with the time series
decomp : 'additive' or 'multiplicative'
iqr_mult : iqr_mult * inter quartile range is used to classify outliers

Methods

detector() : Detect the outliers
remover() (In parent class) : Returns a time series with outliers removed

Example

We use air passenger data as an example for outlier detection model

import pandas as pd
import matplotlib.pyplot as plt
from infrastrategy.kats.consts import TimeSeriesData
from datetime import datetime
from infrastrategy.kats.detectors.outlierDetection import OutlierDetector

data = pd.read_csv("air_passengers.csv")
data.columns = ["time", "y"]
data.loc[data.time == '1950-12-01','y']*=4

TSdata = TimeSeriesData(data)

ts_outlierDetection = OutlierDetector(TSdata, 'multiplicative')

ts_outlierDetection.detector()

fig, ax = plt.subplots(figsize=(20,10))

ax.plot( TSdata.time, TSdata.value)
for i in ts_outlierDetection.outliers[0]:
    dt = datetime.strftime(i, "%Y-%m-%d")
    ax.axvline(i, linewidth=3, linestyle = '--', color='red', alpha = 0.2)

← BOCPD: Bayesian Online Changepoint DetectionACFDetector →
  • API
    • Parameters:
    • Methods
  • Example
Kats Project
More
GitHubStar
Facebook Open Source
Copyright © 2021 Kats Project @ Facebook