hanaml.CrostonTSB is a R wrapper for SAP HANA PAL Croston TSB algorithm.

hanaml.CrostonTSB(
  data,
  key = NULL,
  endog = NULL,
  alpha = NULL,
  beta = NULL,
  forecast.num = NULL,
  method = NULL,
  accuracy.measure = NULL,
  ignore.zero = NULL,
  expost.flag = NULL,
  remove.leading.zeros = NULL,
  massive = FALSE,
  group.params = NULL,
  group.key = NULL
)

Arguments

data

DataFrame
DataFrame containting the data.

key

character, optional
Name of the ID column.
Defaults to the first column if not provided.

endog

character, optional
The endogenous variable, i.e. time series.
Defaults to the first non-ID column.

alpha

double, optional
Value of the smoothing constant alpha (0 < alpha < 1).
Defaults to 0.1.

forecast.num

integer, optional
Number of values to be forecast.
Defaults to 0.

method

character, optional

  • 'sporadic': Use the sporadic method.

  • 'constant': Use the constant method.

Defaults to "sporadic".

accuracy.measure

character or list of characters, optional
Specifies the method of accuracy evaluation.

  • "mpe": Mean percentage error.

  • "mse": Mean squared error.

  • "rmse": Root mean squared error.

  • "et": Error total.

  • "mad": Mean absolute deviation.

  • "mase": Out-of-sample mean absolute scaled error.

  • "wmape": Weighted mean absolute percentage error.

  • "smape": Symmetric mean absolute percentage error.

  • "mape": Mean absolute percentage error.

No default value.

ignore.zero

logical, 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.flag

logical, 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.

remove.leading.zeros

logical, 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.

Defaults to FALSE.

massive

logical, optional
Specifies whether or not to use massive 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:

mcr <- hanaml.CrostonTSB(data=df,
                          massive=TRUE,
                          group.key='ID',
                          expost.flag=FALSE,
                          group.params=list('Group_1'=list('accuracy.measure'='MAPE')))

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.params

list, optional
If the massive mode is activated (massive = TRUE), input data for croston TSB shall be divided into different groups with different parameters applied.
An example is as follows:

mcr <- hanaml.CrostonTSB(data=df,
                          massive=TRUE,
                          group.key='ID',
                          expost.flag=FALSE,
                          group.params=list('Group_1'=list('accuracy.measure'='MAPE')))

Valid only when massive is TRUE and defaults to NULL.

group.key

character, 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 NULL.

Value

Return a list of DataFrames:

  • DataFrame 1
    Forecast values.

  • DataFrame 2
    Statistics.

  • DataFrame 3
    Metrics.

  • DataFrame 4
    Error message (only valid in Massive mode, MASSIVE=TRUE).

Details

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

Examples

Input DataFrame data:


> data$Collect()
   ID RAWDATA
1   0       0
2   1       0
3   2       4
4   3       0
5   4       0
6   5       0
7   6       5
8   7       3
9   8       0
10  9       0
11 10       0

Call the function:


> ctsb <- hanaml.CrostonTSB(data=data,
                            alpha=0.1,
                            beta=0.1,
                            forecast.num=1,
                            expost.flag=TRUE,
                            method="constant",
                            accuracy.measure="mape",
                            remove.leading.zeros=FALSE)

Output:


> ctsb[[2]]$Collect()
  STAT_NAME    STAT_VALUE
1      MAPE       0.89598