python中的季节分解

python中的季节分解,python,matplotlib,machine-learning,time-series,statsmodels,Python,Matplotlib,Machine Learning,Time Series,Statsmodels,我有一个CSV文件,其中包含近5年的平均温度。使用statsmodels.tsa.seasonal中的seasonal\u decompose函数进行分解后,我得到了以下结果。事实上,结果没有显示任何季节性!然而,我在趋势中看到了一个明显的sin!我想知道这是为什么,我如何才能纠正它?多谢各位 nresult = seasonal_decompose(nseries, model='additive', freq=1) nresult.plot() plt.show() 您的频率似乎已关闭 i

我有一个CSV文件,其中包含近5年的平均温度。使用
statsmodels.tsa.seasonal
中的
seasonal\u decompose
函数进行分解后,我得到了以下结果。事实上,结果没有显示任何季节性!然而,我在趋势中看到了一个明显的
sin
!我想知道这是为什么,我如何才能纠正它?多谢各位

nresult = seasonal_decompose(nseries, model='additive', freq=1)
nresult.plot()
plt.show()

您的
频率似乎已关闭

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()


如何正确调整频率?如果我有两年的每周数据,我的频率应该是多少,是freq=52?在这种情况下,它将是空的
# Redo the same thing, but with the known frequency
seasonal_decompose(df, model='additive', freq=365).plot()