Croston
- class hana_ml.algorithms.pal.tsa.exponential_smoothing.Croston(alpha=None, forecast_num=None, method=None, accuracy_measure=None, ignore_zero=None, expost_flag=None)
Croston method is a forecast strategy for products with intermittent demand. Croston method consists of two steps. First, separate exponential smoothing estimates are made of the average size of a demand. Second, the average interval between demands is calculated. This is then used in a form of the constant model to predict the future demand.
- Parameters
- alphafloat, optional
Value of the smoothing constant alpha (0 < alpha < 1).
Defaults to 0.1.
- forecast_numint, optional
Number of values to be forecast.
When it is set to 1, the algorithm only forecasts one value.
Defaults to 0.
- methodstr, optional
'sporadic': Use the sporadic method.
'constant': Use the constant method.
Defaults to 'sporadic'.
- accuracy_measurestr or list of str, optional
The metric to quantify how well a model fits input data. Options: "mpe", "mse", "rmse", "et", "mad", "mase", "wmape", "smape", "mape".
No default value.
Note
Specify a measure name if you want the corresponding measure value to be reflected in the output statistics self.stats_.
- ignore_zerobool, optional
False: Uses zero values in the input dataset when calculating "mpe" or "mape".
True: Ignores zero values in the input dataset when calculating "mpe" or "mape".
Only valid when
accuracy_measure
is "mpe" or "mape".Defaults to False.
- expost_flagbool, optional
False: Does not output the expost forecast, and just outputs the forecast values.
True: Outputs the expost forecast and the forecast values.
Defaults to True.
Examples
Input dataframe df for Croston:
>>> df.collect() ID RAWDATA 0 0.0 1 1.0 2 4.0 3 0.0 4 0.0 5 0.0 6 5.0 7 3.0 8 0.0 9 0.0 10 0.0
Create a Croston instance:
>>> croston = Croston(alpha=0.1, forecast_num=1, method='sporadic', accuracy_measure='mape')
Perform fit on the given data:
>>> croston.fit_predict(data=df)
Output:
>>> croston.forecast_.collect().set_index('ID').head(6) ID RAWDATA 0 0.000000 1 3.025000 2 3.122500 3 0.000000 4 0.000000 5 0.000000
>>> croston.stats_.collect() STAT_NAME STAT_VALUE MAPE 0.2432181818181818
- Attributes
- forecast_DateFrame
Forecast values.
- stats_DataFrame
Statistics analysis content.
Methods
Generate time series report.
fit_predict
(data[, key, endog])Fit and predict based on the given time series.
generate_html_report
([filename])Display function.
Display function.
- fit_predict(data, key=None, endog=None)
Fit and predict based on the given time series.
- Parameters
- dataDataFrame
Input data. At least two columns, one is ID column, the other is raw data.
- keystr, optional
The ID column.
Defaults to the first column of data if the index column of data is not provided. Otherwise, defaults to the index column of data.
- endogstr, optional
The column of series to be fitted and predicted.
Defaults to the first non-ID column.
- Returns
- DataFrame: Forecast values.
- build_report()
Generate time series report.
- property fit_hdbprocedure
Returns the generated hdbprocedure for fit.
- generate_html_report(filename=None)
Display function.
- generate_notebook_iframe_report()
Display function.
- property predict_hdbprocedure
Returns the generated hdbprocedure for predict.