首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sktime无效频率

sktime无效频率
EN

Stack Overflow用户
提问于 2021-02-19 14:00:01
回答 1查看 1.7K关注 0票数 4

我试着从sktime软件包中拟合ARIMA模型。我导入一些数据集并将其转换为熊猫系列。然后,我在列车样本上拟合模型,当我试图预测错误发生时。

代码语言:javascript
复制
from sktime.forecasting.base import ForecastingHorizon
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.forecasting.arima import ARIMA
import numpy as np, pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv',
                 parse_dates=['date']).set_index('date').T.iloc[0]
p, d, q = 3, 1, 2
y_train, y_test = temporal_train_test_split(df, test_size=24)
model = ARIMA((p, d, q))
results = model.fit(y_train)
fh = ForecastingHorizon(y_test.index, is_relative=False,)

# the error is here !!
y_pred_vals, y_pred_int = results.predict(fh, return_pred_int=True)

错误消息如下:

代码语言:javascript
复制
ValueError: Invalid frequency. Please select a frequency that can be converted to a regular
`pd.PeriodIndex`. For other frequencies, basic arithmetic operation to compute durations
currently do not work reliably.

在读取数据集时,我尝试使用.asfreq("M"),但是,本系列中的所有值都变成了NaN

有趣的是,这段代码使用的是来自sktime.datasets的默认sktime.datasets数据集,而不是github中的my。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-20 13:14:54

我得到了一个不同的错误:ValueError: ``unit`` missing,可能是由于版本的差异。无论如何,我要说的是,最好将dataframe的索引作为pd.PeriodIndex而不是pd.DatetimeIndex。前者是我认为更明确的(例如,月系列有它的时间步骤作为周期,而不是确切的日期)和工作更顺利。所以在看了csv之后,

代码语言:javascript
复制
df.index = pd.PeriodIndex(df.index, freq="M")

应该清除错误(在我的版本中是这样做的;0.5.1):

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66278986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档