gpt4 book ai didi

python - python中的季节性分解

转载 作者:太空狗 更新时间:2023-10-29 21:41:39 32 4
gpt4 key购买 nike

我有一个 CSV 文件,其中包含将近 5 年的平均温度。使用 statsmodels.tsa.seasonal 中的 seasonal_decompose 函数进行分解后,我得到了以下结果。事实上,结果不显示任何季节性!但是,我在趋势中看到了明显的错误!我想知道为什么会这样,我该如何纠正它?谢谢。

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

enter image description here

最佳答案

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

enter image description here

# Redo the same thing, but with the known frequency
seasonal_decompose(df, model='additive', freq=365).plot()

enter image description here

关于python - python中的季节性分解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47609537/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com