时间序列--分解

可以分解为四个模块

These components are defined as follows:

  • Level: The average value in the series.
  • Trend: The increasing or decreasing value in the series.
  • Seasonality: The repeating short-term cycle in the series.
  • Noise: The random variation in the series.

可加模型:y(t) = Level + Trend + Seasonality + Noise

可乘模型:y(t) = Level * Trend * Seasonality * Noise

到底用哪一个,需要在程序中指定

from statsmodels.tsa.seasonal import seasonal_decompose
series = ...
result = seasonal_decompose(series, model='additive')
print(result.trend)
print(result.seasonal)
print(result.resid)
print(result.observed)

当然你也可以把这四个对象都画出来

举例:我们原来的数据长这样

Plot of the Airline Passengers Dataset

from pandas import Series
from matplotlib import pyplot
from statsmodels.tsa.seasonal import seasonal_decompose
series = Series.from_csv('airline-passengers.csv', header=0)
result = seasonal_decompose(series, model='multiplicative')
result.plot()
pyplot.show()

分解一下:

Multiplicative Decomposition of Airline Passenger Dataset

The statsmodels library provides an implementation of the naive, or classical, decomposition method in a function called seasonal_decompose(). It requires that you specify whether the model is additive or multiplicative.

Both will produce a result and you must be careful to be critical when interpreting the result. A review of a plot of the time series and some summary statistics can often be a good start to get an idea of whether your time series problem looks additive or multiplicative.

The seasonal_decompose() function returns a result object. The result object contains arrays to access four pieces of data from the decomposition.

For example, the snippet below shows how to decompose a series into trend, seasonal, and residual components assuming an additive model.

The result object provides access to the trend and seasonal series as arrays. It also provides access to the residuals, which are the time series after the trend, and seasonal components are removed. Finally, the original or observed data is also stored.

参考:https://machinelearningmastery.com/decompose-time-series-data-trend-seasonality/

您提到的STL(Seasonal and Trend decomposition using Loess)是一种常用的时间序列分解方法,用于将时间序列分解为趋势、季节性和残差三个部分。如果您想改进STL的时间序列分解,我有以下几点建议: 1. 调整参数:STL中有一些关键参数可以影响分解的效果,例如LOESS窗口大小、季节周期的选择等。您可以尝试不同的参数组合,以获得更好的分解结果。可以使用交叉验证或者其他评估指标来选择最佳参数。 2. 引入外部信息:除了时间序列本身的信息,您可以考虑引入其他相关的外部信息,如天气数据、经济指标等。这些外部信息可能对趋势和季节性的分解有所帮助,从而改善分解结果。 3. 考虑季节性变化:如果您的时间序列具有非常特殊或复杂的季节性变化,可以尝试使用其他更适合的方法来处理,如Fourier变换、Wavelet变换等。这些方法在处理不规则或高阶季节性变化方面可能更有效。 4. 考虑非线性趋势:STL方法假设趋势是线性的,但实际上趋势可能是非线性的。您可以尝试使用其他更适合非线性趋势拟合的方法,如多项式回归、非线性回归等。 5. 数据预处理:在应用STL之前,您可以进行一些数据预处理步骤,如去除异常值、平滑数据等。这些步骤可以帮助提高分解的准确性。 请注意,以上建议是一般性的改进措施,并不针对具体的时间序列。根据您的具体应用场景和数据特点,可能需要进一步定制和优化分解方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值