kats.models.reconciliation.base_models module¶

This module contains 1) helper functions for evaluating forecasting models (i.e., calc_mape and calc_mae); 2) the BaseTHModel class for storing information of base models; and 3) the GetAggregateTS class for aggregating base time series to higher levels.

class kats.models.reconciliation.base_models.BaseTHModel(level: int, model_name: Optional[str] = None, model_params: Optional[object] = None, residuals: Optional[numpy.ndarray] = None, fcsts: Optional[numpy.ndarray] = None)[source]¶

Bases: object

Base class for temporal hierarhical models.

The object stores the information of base model. We allow users to pass model info (i.e., model_name and model_params), or to pass residuals and forecasts of a trained model directly.

level¶

An integer representing the level of the base model, should be a positive integer.

model_name¶

Optional; A string representing the name of forecast model; Default is None.

model_params¶

Optional; A parameter object storing the parameters of forecasting model; Default is None.

residuals¶

Optional; A np.array of residuals of forecasting model, which is necessary if both model_name and model_params are None. Default is None.

fcsts¶

Optional; A np.array of forecasts generated by the forecasting model, which is necessary if both model_name and model_params are None. Default is None.

class kats.models.reconciliation.base_models.GetAggregateTS(data: kats.consts.TimeSeriesData)[source]¶

Bases: object

Class for aggregating time series to different levels.

This class provides aggregate.

data¶

A TimeSeriesData object representing the time series to be aggregated.

aggregate(levels: List[int])Dict[int, kats.consts.TimeSeriesData][source]¶

Function for aggregating time series.

Parameters

levels – A list of integers representing the levels which the time series to be aggregated for.

Returns

A dictionary of aggregated time series for each level.

kats.models.reconciliation.base_models.calc_mae(predictions: numpy.ndarray, truth: numpy.ndarray)float[source]¶

Calculate mae.

MAE = average(abs(truth-predictions))

Parameters
  • predictions – a np.array storing predictions.

  • truth – a np.array storing true values.

Returns

A float representing the MAE.

kats.models.reconciliation.base_models.calc_mape(predictions: numpy.ndarray, truth: numpy.ndarray)float[source]¶

Calculate mape. MAPE = average(abs((truth-predictions)/truth))

Parameters
  • predictions – a np.array storing predictions.

  • truth – a np.array storing true values.

Returns

A float representing the MAPE.