【问题标题】:Statsmodels: ARIMA giving less than specified number of predictionsStatsmodels:ARIMA 给出的预测数量少于指定数量
【发布时间】:2018-03-12 14:05:06
【问题描述】:

我在时间序列问题上使用 ARIMA。具体来说,我使用 Sklearn 的TimeSeriesSplit 来执行交叉验证。不幸的是,当我要求 30 个预测时,我得到了 3 个预测。这就是我所做的:

    Y_train = Y_train.astype(float)
    # build basic ARIMA model
    arima_model = ARIMA(Y_train, order=(2,0,1))
    # fit it
    arima_results = arima_model.fit()
    # predict next len(test) values
    preds = arima_results.forecast(steps=len(Y_test))
    print("len of y_train:", len(Y_train))
    print("len of y_test:", len(Y_test))
    print("len of preds:", len(preds))

然后我回来了:

len of y_train: 56
len of y_test: 30
len of preds: 3

当我去计算 mean_squared_error 时,这会导致错误,因为预测的长度 (3) 与我的测试集 (30) 不同。这是错误:

ValueError: Found input variables with inconsistent numbers of samples: [3, 30]

知道我在搞砸什么吗?

谢谢!

【问题讨论】:

    标签: python statsmodels arima


    【解决方案1】:

    From the documentation, fit 返回一个ARIMAResults 的实例,它提供了forecast 方法。

    return value is a tuple,其中每个元素都是具有不同类型结果计算的合适长度的数组。所以看来你想合作

    preds[0]
    

    而不是直接看preds

    【讨论】:

      猜你喜欢
      • 2019-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-07
      • 1970-01-01
      • 1970-01-01
      • 2015-10-31
      • 2021-06-18
      相关资源
      最近更新 更多