kats.utils.emp_confidence_int module

The Empirical Confidence (Prediction) Interval

This is an empirical way to estimate the prediction interval for any forecasting models The high level idea is to estimate the empirical error distributions from a specific forecasting model, and use linear regression model to fit the standard error (S.E.) with the time horizon, under the assumption that longer horizon has larger S.E.

class kats.utils.emp_confidence_int.EmpConfidenceInt(error_methods: List[str], data: kats.consts.TimeSeriesData, params: kats.consts.Params, train_percentage: float, test_percentage: float, sliding_steps: int, model_class, multi=True, confidence_level: float = 0.8, **kwargs)[source]

Bases: object

“class for empirical confidence interval

The steps are listed as follows: 1. Run K-fold CV for a given model and data,

each fold contains h (horizon) time ahead

  1. For each horizon, calculate the Std of K error terms (S.E)

  2. Fit linear model: S.E. ~ Horizon

  3. Estimate the S.E. for each horizon for the true future

  4. Lower/Upper = Point Estimate -/+ Z_Score * S.E.

error_method

list of strings indicating which errors to calculate we currently support “mape”, “smape”, “mae”, “mase”, “mse”, “rmse”

data

the time series data in TimeSeriesData format

params

the Kats model parameter object

train_percentage

percentage of data used for training

test_percentage

percentage of data used for testing

sliding_steps

number of rolling steps to take (# of folds)

model_class

the Kats model class

multi

flag to use multiprocessing, the default is True

confidence_level

the confidence level for the prediction interval

diagnose()[source]

Diagnose the linear model fit for SE

Plot the OLS fit: SE ~ Horizon

Parameters

None

Returns

None

get_eci(steps: int, **kwargs)[source]

Get empirical prediction interval

Parameters

steps – the length of forecasting horizon

Returns

The dataframe of forecasted values with prediction intervals

get_lr()[source]

Fit linear regression model

Fit linear regression model for std ~ horizon return the fitted model

Parameters

None

Returns

None

plot()[source]

Make plot for model fitting with new uncertainty intervals

Parameters

None

Returns

None

run_cv()[source]

Running the cross validation process

run cv with given model and data get errors for each horizon as follows

horizon | error |
1 | 12.3 |

then calculate the std for each horizon
horizon | std |
1 | 1.2 |
Parameters

None

Returns

None