时间序列--分解

可以分解为四个模块

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/

猜你喜欢

转载自blog.csdn.net/kylin_learn/article/details/85309576
今日推荐