CrostonTSB

class hana_ml.algorithms.pal.tsa.exponential_smoothing.CrostonTSB(alpha=None, beta=None, forecast_num=None, method=None, accuracy_measure=None, ignore_zero=None, expost_flag=None, remove_leading_zeros=None, massive=False, group_params=None)

Croston TSB method (for Teunter, Syntetos & Babai) is a forecast strategy for products with intermittent demand. It is a modification of Croston's method.

It replaces the demand interval in Croston's method by demand probability which is updated every period. Compared to Croston's method, the forecast of TSB method is not biased and its probability forecast can be used to estimate the risk of obsolescence.

Parameters:
alphafloat, optional

Smoothing parameter for demand.

Defaults to 0.1.

betafloat, optional

Smoothing parameter for probability.

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 a 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_.

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.

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.

remove_leading_zerosbool, optional
  • False: Uses leading zero values in the input dataset when smoothing the probability;

  • True: Ignores leading zero values in the input dataset when smoothing the probability.

When it is set to 1, the leading zeros are ignored for calculating measure.

Defaults to False.

massivebool, optional

Specifies whether or not to use massive mode of croston TSB.

  • True : massive mode.

  • False : single mode.

For parameter setting in massive mode, you could use both group_params (please see the example below) or the original parameters. Using original parameters will apply for all groups. However, if you define some parameters of a group, the value of all original parameter setting will be not applicable to such group.

An example is as follows:

In this example, as 'accuracy_measure' is set in group_params for Group_1, parameter setting of 'expost_flag' is not applicable to Group_1.

Defaults to False.

group_paramsdict, optional

If massive mode is activated (massive is True), input data for croston TSB shall be divided into different groups with different parameters applied.

An example is as follows:

Valid only when massive is True and defaults to None.

Examples

>>> cr = CrostonTSB(alpha=0.3, beta=0.1, forecast_num=10,
                    method='constant', accuracy_measure=['mape'],
                    expost_flag=True, ignore_zero=False, remove_leading_zeros=False)

Perform fit_predict():

>>> forecast = cr.fit_predict(data=df)

Output:

>>> forecast.collect()
>>> cr.stats_.collect()
>>> cr.metrics_.collect()
Attributes:
forecast_DateFrame

Forecast values.

stats_DataFrame

Statistics analysis.

metrics_DataFrame

Metrics Value.

error_msg_DataFrame

Error message. Only valid if massive is True when initializing a 'CrostonTSB' instance.

Methods

fit_predict(data[, key, endog, group_key])

Fit and predict based on the given time series.

get_model_metrics()

Get the model metrics.

get_score_metrics()

Get the score metrics.

fit_predict(data, key=None, endog=None, group_key=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.

In single mode, defaults to the first column of data if the index column of data is not provided. Otherwise, defaults to the index column of data.

In massive mode, defaults to the first-non group key column of data if the index columns of data is not provided. Otherwise, defaults to the second of index columns of data and the first column of index columns is group_key.

endogstr, optional

The column of series to be fitted and predicted.

In single mode, defaults to the first non-ID column. In massive mode, defaults to the first non group_key, non key column.

group_keystr, optional

The column of group_key. The data type can be INT or NVARCHAR/VARCHAR. If data type is INT, only parameters set in the group_params are valid.

This parameter is only valid when massive is True.

Defaults to the first column of data if the index columns of data is not provided. Otherwise, defaults to the first column of index columns.

Returns:
DataFrame

Forecast values.

get_model_metrics()

Get the model metrics.

Returns:
DataFrame

The model metrics.

get_score_metrics()

Get the score metrics.

Returns:
DataFrame

The score metrics.

Inherited Methods from PALBase

Besides those methods mentioned above, the CrostonTSB class also inherits methods from PALBase class, please refer to PAL Base for more details.