程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了时间序列的分解:ValueError: You must specified a period or x must be an pandas object with a DatetimeIndex with a freq not set to None大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决时间序列的分解:ValueError: You must specified a period or x must be an pandas object with a datetiR_982_11845@eIndex with a freq not set to None?

开发过程中遇到时间序列的分解:ValueError: You must specified a period or x must be an pandas object with a datetiR_982_11845@eIndex with a freq not set to None的问题如何解决?下面主要结合日常开发的经验,给出你关于时间序列的分解:ValueError: You must specified a period or x must be an pandas object with a datetiR_982_11845@eIndex with a freq not set to None的解决方法建议,希望对你解决时间序列的分解:ValueError: You must specified a period or x must be an pandas object with a datetiR_982_11845@eIndex with a freq not set to None有所启发或帮助;

给定一个来自 this link 的交通流数据集,日期范围是从 2021-01-012021-01-15,对于每一天的小时范围是 10:00:0212:00:00,其中2minutes 的频率。@H_944_13@

df.head()
Out[145]: 
   trafic flow count                date
0               30.0 2021-01-01 10:02:00
1               38.0 2021-01-01 10:04:00
2               27.0 2021-01-01 10:06:00
3               31.0 2021-01-01 10:08:00
4               29.0 2021-01-01 10:10:00

df.tail()
Out[146]: 
     trafic flow count                date
895               28.0 2021-01-15 11:52:00
896               41.0 2021-01-15 11:54:00
897               19.0 2021-01-15 11:56:00
898               15.0 2021-01-15 11:58:00
899               18.0 2021-01-15 12:00:00

下一步我需要使用 ARIMA 模型来预测 2021-01-16 的流量,但在分解过程中出现错误:@H_944_13@

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.stattools import adfuller
from statsmodels.tsa.seasonal import seasonal_decompose

df = pd.read_excel('data.xLSX')
df = df.set_index('date')
def adf_test(timeserIEs):
    # perform Dickey-Fuller test:
    print ('Results of Dickey-Fuller Test:')
    dftest = adfuller(timeserIEs,autolag='AIC')
    dfoutput = pd.SerIEs(dftest[0:4],index=['Test Statistic','p-value','#Lags Used','number of Observations Used'])
    for key,value in dftest[4].items():
       dfoutput['Critical Value (%s)'%key] = value
    print (dfoutput)

# apply adf test on the serIEs
adf_test(df['trafic flow count'])

df_log = np.log(df)
plt.plot(df_log)

decomposition = seasonal_decompose(df_log)
trend = decomposition.trend
seasonal = decomposition.seasonal
resIDual = decomposition.resID

plt.figure(figsize=(20,7))
plt.subplot(411)
plt.plot(df_log,label="Original")
plt.legend(loc="best")
plt.subplot(412)
plt.plot(trend,label="Trend")
plt.legend(loc="best")
plt.subplot(413)
plt.plot(seasonal,label="Seasonability")
plt.legend(loc="best")
plt.subplot(414)
plt.plot(resIDual,label="ResIDuals")
plt.legend(loc="best")
plt.tight_layout()

出:@H_944_13@

ValueError: You must specify a period or x must be a pandas object with a datetiR_982_11845@eIndex with a freq not set to None

为什么我会收到此错误以及如何修复它?谢谢。@H_944_13@

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!@H_944_13@

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。@H_944_13@

小编邮箱:dio#foxmail.com (将#修改为@)@H_944_13@

大佬总结

以上是大佬教程为你收集整理的时间序列的分解:ValueError: You must specified a period or x must be an pandas object with a DatetimeIndex with a freq not set to None全部内容,希望文章能够帮你解决时间序列的分解:ValueError: You must specified a period or x must be an pandas object with a DatetimeIndex with a freq not set to None所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。