kats.models.ensemble.kats_ensemble module¶
Kats ensemble model
Implementation of the Kats ensemble model. It starts from seasonality detection, if seasonality detected, it continues to perform STL decomposition, then fit forecasting models on de-seasonalized components and aggregate; otherwise it simiply leverage individual forecasting models and ensembling. We provided two ensembling methods, weighted average and median ensembling.
- class kats.models.ensemble.kats_ensemble.KatsEnsemble(data: kats.consts.TimeSeriesData, params: Dict[str, Any])[source]¶
- Bases: - object- Decomposition based ensemble model in Kats This is the holistic ensembling class based on decomposition when seasonality presents - aggregate() → pandas.core.frame.DataFrame[source]¶
- Aggregate the results from predict method - Parameters
- None – 
- Returns
- final results in pd.DataFrame 
 
 - backTestExecutor() → Dict[str, float][source]¶
- wrapper for back test executor - services which use KatsEnsemble need to write their own backtest wrapper - Parameters
- None – 
- Returns
- The dict of backtesting results 
 
 - static clean_dummy_CI(fcsts: Dict[str, pandas.core.frame.DataFrame], use_zero: bool = True) → Dict[str, pandas.core.frame.DataFrame][source]¶
- Helper method to clean dummy prediction interval - Parameters
- fcsts – the dict of forecasting results from individual models 
- use_zero – flag to use zero to fill nan, default as True 
 
- Returns
- the cleaned results in a dict 
 
 - static deseasonalize(data: kats.consts.TimeSeriesData, decomposition_method: str) → Tuple[kats.consts.TimeSeriesData, kats.consts.TimeSeriesData][source]¶
- STL decomposition to given TimeSeriesData - Static method to perform decomposition on the input data - Parameters
- data – - kats.consts.TimeSeriesData, input time series data
- decomposition_method – the specific method for decomposition 
 
- Returns
- Tuple of seasonal data and de-seasonalized data 
 
 - fit() → kats.models.ensemble.kats_ensemble.KatsEnsemble[source]¶
- Fit individual forecasting models via calling fitExecutor - This is the fit methdo to fit individual forecasting model 
 - fitExecutor(data: kats.consts.TimeSeriesData, models: kats.models.ensemble.ensemble.EnsembleParams, should_auto_backtest: bool = False) → Tuple[Dict[Any, Any], Optional[Dict[str, float]]][source]¶
- callable forecast executor - This is native implementation with Python’s multiprocessing fit individual model in models with given data. Services who use KatsEnsemble need to implement their own executor for better performance, if no executor function is given, the native version will be used. - data¶
- kats.consts.TimeSeriesData, given TimeSeriesData, could be original or de-seasonalized
 - models¶
- EnsembleParams object containing model params in BaseModelParams 
 - should_auto_backtest¶
- boolean flag for additional back testing runs 
 - Returns
- Tuple of fitted individual model and weights 
 
 - forecast(steps: int) → Tuple[Dict[str, pandas.core.frame.DataFrame], Optional[Dict[str, float]]][source]¶
- Holistic forecast method in Kats ensemble - combine fit and predict methods to produce forecasted results this is especially useful for services which prefer to produce final forecasts without saving the fitted model - Parameters
- steps – the length of forecasting horizon 
- Returns
- Tuple of predicted values and weights 
 
 - forecastExecutor(data: kats.consts.TimeSeriesData, models: kats.models.ensemble.ensemble.EnsembleParams, steps: int, should_auto_backtest: bool = False) → Tuple[Dict[str, pandas.core.frame.DataFrame], Optional[Dict[str, float]]][source]¶
- Forecast Executor - This is a callable execution function to (1). fit model (2). predict with a given steps (3). back testing (optional) - Parameters
- data – - kats.consts.TimeSeriesData, the input time series data as in- kats.consts.TimeSeriesData
- models – the ensemble parameters as in EnsembleParams 
- steps – the length of forecasting horizon 
- should_auto_backtest – flag to automatically perform back test, default as False 
 
- Returns
- The predicted values from each individual model and weights 
 
 - predict(steps: int) → kats.models.ensemble.kats_ensemble.KatsEnsemble[source]¶
- Predit future for each individual model - Parameters
- steps – number of steps ahead to forecast 
- Returns
- None 
 
 - static reseasonalize(sea_data: kats.consts.TimeSeriesData, desea_predict: Dict[str, pandas.core.frame.DataFrame], decomposition_method: str, seasonality_length: int, steps: int) → Dict[str, pandas.core.frame.DataFrame][source]¶
- Re-seasonalize the time series data - Static method to re-seasonalize the input data - Parameters
- sea_data – - kats.consts.TimeSeriesData, the seasonal data from deseasonalize method
- desea_predict – dict of forecasted results for the deseasonalized data for each individual forecasting method 
- decomposition_method – the specific method for decomposition 
- seasonality_lenth – the length of seasonality 
- steps – the length of forecasting horizon 
 
- Returns
- Dict of re-seasonalized data for each individual forecasting model 
 
 - static seasonality_detector(data) → bool[source]¶
- Detect seasonalities from given TimeSeriesData - Parameters
- data – - kats.consts.TimeSeriesData, the input TimeSeriesData
- Returns
- Flag for the presence of seasonality