4

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

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)

错误消息如下:

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.
有趣的是,这段代码适用于来自 github 的默认load_airline数据集,sktime.datasets但不适用于我来自 github 的数据集。

4

1 回答 1

3

我得到一个不同的错误:ValueError: ``unit`` missing,可能是由于版本差异。无论如何,我会说最好让你的数据框的索引pd.PeriodIndex而不是pd.DatetimeIndex. 前者我认为更明确(例如,每月系列的时间步长为时期而不是确切日期)并且工作更顺利。所以在阅读了csv之后,

df.index = pd.PeriodIndex(df.index, freq="M")

应该清除错误(它在我的版本中;0.5.1): F

于 2021-02-20T13:14:54.300 回答