sktime ARIMA 无效频率

sktime ARIMA invalid frequency

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

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

的我的数据集

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

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

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