Jos*_*osh 4 python time-series pandas statsmodels arima
我正在尝试使用 SciKitLearn 在时间序列数据集上运行样本外验证TimeSeriesSplit()
来创建训练/测试折叠。
这个想法是在训练折叠上训练 Statsmodel 的 SARIMAX,然后在测试折叠上进行验证,而无需重新拟合模型。为此,我们必须在预测之前将测试折叠中的新观察结果一次一次地迭代附加到模型中。
但是,我在该附加步骤中收到 ValueError:
ValueError: Given `endog` does not have an index that extends the index of the model.
这对我来说毫无意义。如果我打印print(max(train_fold.index), min(test_fold.index))
每次折叠,显然序列折叠的最后一个索引低于测试折叠的第一个索引。就我而言:
1983-05 1983-06
1984-05 1984-06
1985-05 1985-06
1986-05 1986-06
1987-05 1987-06
Run Code Online (Sandbox Code Playgroud)
这是当前的完整代码。我确信我在做一些愚蠢的事情,但我被困住了:
1983-05 1983-06
1984-05 1984-06
1985-05 1985-06
1986-05 1986-06
1987-05 1987-06
Run Code Online (Sandbox Code Playgroud)
这model_fitted.append(next_row, refit=False)
是故障点。有任何想法吗?谢谢!
知道了!这太愚蠢了。
.append()
SARIMAX 模型的方法返回模型本身,而不是更改模型中存储的数据。
所以正确的代码很简单:
model_fitted = model_fitted.append(next_row, refit=False)