LR_seasonal_adjust
- class hana_ml.algorithms.pal.tsa.lr_seasonal_adjust.LR_seasonal_adjust(forecast_length=None, trend=None, affect_future_only=None, seasonality=None, seasonal_period=None, accuracy_measure=None, seasonal_handle_method=None, expost_flag=None, ignore_zero=None)
Linear regression with damped trend and seasonal adjust is an approach for forecasting when a time series presents a trend. It provides a damped smoothing parameter for smoothing the forecasted values. This dampening parameter avoids the over-casting due to the “indefinitely” increasing or decreasing trend. In addition, if the time series presents seasonality, you can deal with it by providing the length of the periods in order to adjust the forecasting results. On the other hand, it also helps you to detect the seasonality and to determine the periods.
- Parameters:
- forecast_lengthint, optional
Specifies the length of forecast results.
Defaults to 1.
- trendfloat, optional
Specifies the damped trend factor, with valid range (0, 1].
Defaults to 1.
- affect_future_onlybool, optional
Specifies whether the damped trend affect future only or it affects the entire history.
Defaults to True.
- seasonalityint, optional
Specifies whether the data represents seasonality.
0: Non-seasonality.
1: Seasonality exists and user inputs the value of periods.
2: Automatically detects seasonality.
Defaults to 0.
- seasonal_periodint, optional
Length of seasonal_period.seasonal_period is only valid when seasonality is 1.
If this parameter is not specified, the seasonality value will be changed from 1 to 2, that is, from user-defined to automatically-detected.
No default value.
- seasonal_handle_method{'average', 'lr'}, optional
Method used for calculating the index value in the seasonal_period.
'average': Average method.
'lr': Fitting linear regression.
Defaults to 'average'.
- 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_.
- 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
>>> lr = LR_seasonal_adjust(forecast_length=10, trend=0.9, affect_future_only=True, seasonality=1, seasonal_period=4, accuracy_measure='mse')
Perform fit_predict():
>>> lr.fit_predict(data=df)
Output:
>>> lr.forecast_.collect() >>> lr.stats_.collect()
- Attributes:
- forecast_DataFrame
Forecast values.
- stats_DataFrame
Statistics.
Methods
fit_predict
(data[, key, endog])Fit and predict based on the given time series.
Get the model metrics.
Get the score metrics.
- 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.
- 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 LR_seasonal_adjust class also inherits methods from PALBase class, please refer to PAL Base for more details.