python中的季节性分解 [英] seasonal decompose in python
本文介绍了python中的季节性分解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个CSV文件,其中包含近5年的平均温度.使用 statsmodels.tsa.seasonal
中的 seasonal_decompose
函数分解后,我得到了以下结果.确实,结果没有显示任何季节性!但是,我在趋势中看到了明显的 sin
!我想知道为什么会这样,我该如何纠正呢?谢谢.
I have a CSV file that contains the average temperature over almost 5 years. After decomposition using seasonal_decompose
function from statsmodels.tsa.seasonal
, I got the following results. Indeed, the results do not show any seasonal! However, I see a clear sin
in the trend! I am wondering why is that and how can I correct it? Thank you.
nresult = seasonal_decompose(nseries, model='additive', freq=1)
nresult.plot()
plt.show()
推荐答案
您的 freq
似乎已关闭.
import numpy as np
import pandas as pd
from statsmodels.tsa.seasonal import seasonal_decompose
# Generate some data
np.random.seed(0)
n = 1500
dates = np.array('2005-01-01', dtype=np.datetime64) + np.arange(n)
data = 12*np.sin(2*np.pi*np.arange(n)/365) + np.random.normal(12, 2, 1500)
df = pd.DataFrame({'data': data}, index=dates)
# Reproduce the example in OP
seasonal_decompose(df, model='additive', freq=1).plot()
# Redo the same thing, but with the known frequency
seasonal_decompose(df, model='additive', freq=365).plot()
这篇关于python中的季节性分解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文