statsmodels.tsa.seasonal.seasonal_decompose#
- statsmodels.tsa.seasonal.seasonal_decompose(x, model='additive', filt=None, period=None, two_sided=True, extrapolate_trend=0)[source]#
Seasonal decomposition using moving averages.
- Parameters:
- xarray_like
Time series. If 2d, individual series are in columns. x must contain 2 complete cycles.
Changed in version 0.16.0: A DataFrame with more than one column is decomposed column by column, as a 2d ndarray is, and the components are DataFrames with the index and columns of x. It used to raise a TypeError.
- model{“additive”, “multiplicative”},
optional Type of seasonal component. The abbreviations “add” and “mul” are accepted.
- filtarray_like,
optional The filter coefficients for filtering out the seasonal component. The concrete moving average method used in filtering is determined by two_sided.
- period
int,optional Period of the series (eg, 1 for annual, 4 for quarterly, etc). Must be used if x is not a pandas object or if the index of x does not have a frequency. Overrides default periodicity of x if x is a pandas object with a timeseries index.
- two_sidedbool,
optional The moving average method used in filtering. If True (default), a centered moving average is computed using the filt. If False, the filter coefficients are for past values only.
- extrapolate_trend
intor ‘period’,optional If set to > 0, the trend resulting from the convolution is linear least-squares extrapolated on both ends (or the single one if two_sided is False) considering this many (+1) closest points. If set to ‘period’, use period closest points. Setting this parameter results in no NaN values in trend or resid components. The default is 0.
Deprecated since version 0.14:
extrapolate_trend="freq"is deprecated and will be removed in 0.16, useextrapolate_trend="period"instead.
- Returns:
DecomposeResultAn object with seasonal, trend, and resid attributes.
See also
statsmodels.tsa.filters.bk_filter.bkfilterBaxter-King filter.
statsmodels.tsa.filters.cf_filter.cffilterChristiano-Fitzgerald asymmetric, random walk filter.
statsmodels.tsa.filters.hp_filter.hpfilterHodrick-Prescott filter.
statsmodels.tsa.filters.hamilton_filter.hamilton_filterHamilton’s autoregression-based filter.
statsmodels.tsa.filters.convolution_filterLinear filtering via convolution.
statsmodels.tsa.seasonal.STLSeason-Trend decomposition using LOESS.
Notes
This is a naive decomposition. More sophisticated methods should be preferred.
The additive model is Y[t] = T[t] + S[t] + e[t]
The multiplicative model is Y[t] = T[t] * S[t] * e[t]
The results are obtained by first estimating the trend by applying a convolution filter to the data. The trend is then removed from the series and the average of this de-trended series for each period is the returned seasonal component.