Python中的时间序列分解函数 [英] Time Series Decomposition function in Python
本文介绍了Python中的时间序列分解函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
时间序列分解是一种将时间序列数据集分成三个(或更多)组件的方法.例如:
Time series decomposition is a method that separates a time-series data set into three (or more) components. For example:
x(t) = s(t) + m(t) + e(t)
哪里
t is the time coordinate
x is the data
s is the seasonal component
e is the random error term
m is the trend
在 RI 中将执行以下功能 分解
和stl
.我将如何在 python 中执行此操作?
In R I would do the functions decompose
and stl
. How would I do this in python?
推荐答案
我遇到了类似的问题,正在努力寻找最佳的前进道路.尝试将您的数据移动到 Pandas DataFrame 中,然后调用 StatsModels tsa.seasonal_decompose
.请参阅以下示例:
I've been having a similar issue and am trying to find the best path forward. Try moving your data into a Pandas DataFrame and then call StatsModels tsa.seasonal_decompose
. See the following example:
import statsmodels.api as sm
dta = sm.datasets.co2.load_pandas().data
# deal with missing values. see issue
dta.co2.interpolate(inplace=True)
res = sm.tsa.seasonal_decompose(dta.co2)
resplot = res.plot()
然后您可以从以下位置恢复分解的各个组件:
You can then recover the individual components of the decomposition from:
res.resid
res.seasonal
res.trend
我希望这会有所帮助!
这篇关于Python中的时间序列分解函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文