seasonal_decompose

hana_ml.algorithms.pal.tsa.seasonal_decompose.seasonal_decompose(data, key=None, endog=None, alpha=None, thread_ratio=None, model=None, decompose_type=None, extrapolation=None, smooth_width=None, auxiliary_normalitytest=None, periods=None, decompose_method=None, stl_robust=None, stl_seasonal_average=None, smooth_method_non_seasonal=None)

Seasonal_decompose function tests whether a time series has a seasonality or not. If it does, the corresponding additive or multiplicative seasonality model is identified, and the series is decomposed into three components: seasonal, trend, and random.

Parameters:
dataDataFrame

Input data. It should have at least two columns; the ID column and the raw data column.

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

Defaults to the first non-ID column.

alphafloat, optional

The criterion for the autocorrelation coefficient. It ranges between 0 and 1. A higher value implies a more stringent requirement for seasonality.

Defaults to 0.2.

thread_ratiofloat, optional

Adjusts the percentage of available threads to use, from 0 to 1. A value of 0 indicates the use of a single thread, while 1 implies the use of all possible current threads. Values outside the range will be ignored and this function heuristically determines the number of threads to use.

Defaults to -1.

decompose_type{'additive', 'multiplicative', 'auto'}, optional

Specifies the decompose type.

  • 'additive': Additive decomposition model.

  • 'multiplicative': Multiplicative decomposition model.

  • 'auto': Decomposition model automatically determined from input data.

Defaults to 'auto'.

extrapolationbool, optional

Specifies whether to extrapolate the endpoints or not. Set to True when there is an end-point issue.

Defaults to False.

smooth_widthint, optional

Specifies the width of the moving average applied to non-seasonal data. 0 indicates linear fitting to extract trends. Can not be larger than half of the data length.

Defaults to 0.

auxiliary_normalitytestbool, optional

Specifies whether to use normality test to identify model types.

Defaults to False.

periodsint, optional

The length of the periods. When this parameter is specified between 2 and half of the series length, autocorrelation value is calculated for this number of periods and the result is compared to alpha parameter.

If correlation value is equal to or higher than alpha, decomposition is executed with the value of periods. Otherwise, decomposition is executed with no seasonality. For other value of periods, decomposition is also executed with no seasonality.

Defaults to None.

decompose_methodstr, optional

Specifies the decomposition method.

  • 'traditional'.

  • 'stl'.

Defaults to 'traditional'.

stl_robustbool, optional

Whether to use residual weights during STL decomposition. Residual weights can make STL decomposition more robust to outliers.

  • False : Does not use residual weights.

  • True : Uses residual weights.

Only valid when decompose_method is 'stl'.

Defaults to True.

stl_seasonal_averagebool, optional

Whether to make seasonal data equal in every seasonal cycle.

For example, for the seasonal data of a monthly time series with a period of 12, we can get 12 subseries, corresponding to each month. "True" means we take average for each subseries and get the seasonal component for each month. "False" means we do not take the avarage.

Only valid when decompose_method is 'stl'.

Defaults to False.

smooth_method_non_seasonalstr, optional

Specifies the smoothing method for non-seasonal time series.

  • 'moving_average'.

  • 'super_smoother'.

Defaults to 'moving_average'.

Returns:
DataFrames

DataFrame 1 : Statistics

DataFrame 2 : Seasonal decomposition

  • ID column of input data.

  • SEASONAL: seasonality component.

  • TREND: trend component.

  • RANDOM: white noise component.

Examples

>>> stats, decompose = seasonal_decompose(data=df, key='ID', endog='SERIES', alpha=0.2)
>>> stats.collect()
>>> decompose.collect()