Hierarchical_Forecast
- class hana_ml.algorithms.pal.tsa.hierarchical_forecast.Hierarchical_Forecast(method=None, weights=None)
Hierarchical forecast algorithm forecast across the hierarchy (that is, ensuring the forecasts sum appropriately across the levels).
- Parameters:
- method{'optimal_combination', 'bottom_up', 'top_down'}, optional
Method for reconciling forecasts across hierarchy.
Default to 'optimal_combination'.
- weights{'ordinary_least_squares', 'minimum_trace', 'weighted_least_squares'}, optional
Only valid when parameter method is 'optimal_combination'.
Default to 'ordinary_least_squares'.
Examples
Input DataFrames:
>>> orig_df.collect().head(5) Series TimeStamp Original Residual 0 Total 1992 48.748080 0.058252 1 Total 1993 49.480469 0.236069 2 Total 1994 49.932384 -0.044405 3 Total 1995 50.240702 -0.188002 4 Total 1996 50.608464 -0.128558
>>> pred_df.collect().head(5) Series TimeStamp VALUE 0 Total 1993 54.711279 1 Total 1994 54.207598 2 Total 1995 54.703918 3 Total 1996 55.200238 4 Total 1997 55.696558
>>> stru_df.collect().head(5) Index Series NUM 0 1 Total 2 1 2 A 3 2 3 B 2 3 4 AA 0 4 5 AB 0
Create a Hierarchical_Forecast instance:
>>> hr = Hierarchical_Forecast(method='optimal_combination', weights='minimum_trace')
Perform fit_predict():
>>> stats_tbl, result_tbl = hr.fit_predict(orig_data=orig_df, pred_data=pred_df, stru_data=stru_df)
Output:
>>> result_tbl.collect().head(5) Series TimeStamp VALUE 0 Total 1993 48.862705 1 Total 1994 54.255631 2 Total 1995 54.663688 3 Total 1996 55.192436 4 Total 1997 55.719965
- Attributes:
- result_DataFrame
Forecast result.
- stats_DataFrame
Statistics.
Methods
fit_predict
(orig_data, pred_data, stru_data)Apply hierarchical forecast to the input DataFrames.
- fit_predict(orig_data, pred_data, stru_data, orig_name=None, orig_key=None, orig_endog=None, orig_residual=None, pred_name=None, pred_key=None, pred_endog=None)
Apply hierarchical forecast to the input DataFrames.
- Parameters:
- orig_dataDataFrame
DataFrame of original data.
- pred_dataDataFrame
DataFrame of predictive data.
- stru_dataDataFrame
DataFrame of structure data.
- orig_namestr, optional
Name of the time series name column.
- orig_keystr, optional
Name of the time stamp column.
- orig_endogstr, optional
Name of the raw data column.
- orig_residualstr, optional
Name of the residual value column.
- pred_namestr, optional
Name of time series name column.
- pred_keystr, optional
Name of the time stamp column.
- pred_endogstr, optional
Name of the predictive raw data column.
Inherited Methods from PALBase
Besides those methods mentioned above, the Hierarchical_Forecast class also inherits methods from PALBase class, please refer to PAL Base for more details.