• API

›Forecasting

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

Theta

The theta method of Assimakopoulos and Nikolopoulos (2000) is a univariate forecasting method that decomposes the original timeseries into two different Theta-lines (the Theta=0 (straight line) and Theta=2 (double local curves)) and generates forecasts by extrapolating them individually and combining the results.Hyndman and Billah (2003) demonstrated that this is equivalent to simple exponential smoothing with drift. Prediction intervals are calculated using this underlying model.

The timeseries is tested for seasonality using the test outlined in A&N. If deemed seasonal, the series is seasonally adjusted using a classical multiplicative decomposition before applying the theta method. The resulting forecasts are then reseasonalized.

This implementation is similar to the thetaf function in R

API

# Parameter class
class ThetaParams(m=1)

Parameters:

m: optional, number of observations before the seasonal pattern repeats
   For ex, m=12 for montly data with yearly seasonality
   Defauts to 1 indicating no seasonality
# Model class
class ThetaModel(data, params)

Methods

fit(): # fit Theta model with given parameters
predict(steps, freq, alpha): # predict for future steps
Args:
    steps: Number of time steps to forecast
    freq: optional, frequency of timeseries data.
        Defaults to automatically inferring from time index.
    alpha: optional, significance level of condifence interval.
        Defaults to 0.05
plot(): # plot the timeseries data with prediction internal (if exist)

Example

We use air passenger data as an example for Theta model

import pandas as pd
from infrastrategy.kats.consts import TimeSeriesData
from infrastrategy.kats.models.theta import ThetaModel, ThetaParams

# read data and rename the two columns required by TimeSeriesData structure
data = pd.read_csv("../data/example_air_passengers.csv")
data.columns = ["time", "y"]
TSdata = TimeSeriesData(data)

# create ThetaParam with specifying seasonality param value
params = ThetaParams(m=12)

# create ThetaModel with given data and parameter class
m = ThetaModel(data=TSdata, params=params)

# call fit method to fit model
m.fit()

# call predict method to predict the next 15 steps
res = m.predict(steps=15, alpha=0.2)

# visualize the results
m.plot()

Note that the confidence intervals generated are quite narrow. The reason behind this is stated in Hyndman et. al - "this formula for standard error does not include the variation due to estimation error and will therefore give intervals which are too narrow“. Consider using empirical confidence interval estimation implemented in Kats for overcoming this limitations.

← STLFHolt-Winter’s →
  • API
    • Parameters:
    • Methods
  • Example
Kats Project
More
GitHubStar
Facebook Open Source
Copyright © 2021 Kats Project @ Facebook