'numpy.ndarray'对象没有属性'predict'

时间:2019-10-25 14:44:17

标签: python-3.x time-series forecasting arima

我已经完成了对训练数据的预测建模。现在,我想使用“预测”功能绘制一个预测,以用我的测试数据对其进行评估。但是我的代码不起作用 我收到如下错误

文件“”,第1行,在     Fcast = projections_ARIMA.values.predict(开始= '11 / 08/2019',结束= '22 / 09/2019')

AttributeError:“ numpy.ndarray”对象没有属性“ predict”

能帮我吗? 非常感谢 !!!

#modelling
    model = ARIMA(ts_log, order=(1, 1, 1))  
    results_ARIMA= model.fit(disp=-1)  
    plt.plot(ts_log_diff)
    plt.plot(results_ARIMA.fittedvalues, color='red')
    plt.title('RSS: %.4f'% sum((results_MA.fittedvalues-ts_log_diff)**2))
    plt.title('Fitting data _ MSE: %.2f'% ((
            (results_MA.fittedvalues-ts_log_diff)**2).mean()))
    plt.xlabel('Date')
    plt.legend(('Real Log Values', 'Predicted Log Values'), loc='lower right')


    predictions_ARIMA_diff = pd.Series(results_ARIMA.fittedvalues, copy=True)
    print (predictions_ARIMA_diff.head())

    predictions_ARIMA_diff_cumsum = predictions_ARIMA_diff.cumsum()
    print (predictions_ARIMA_diff_cumsum.head())


    predictions_ARIMA_log = pd.Series(ts_log.ix[0], index=ts_log.index)
    predictions_ARIMA_log = predictions_ARIMA_log.add(predictions_ARIMA_diff_cumsum,
                                                      fill_value=0)
    predictions_ARIMA_log.head(20)

    def mean_sqared_err(y,yhat):
        return (sum((yhat-y)**2)/len(y))
    def mean_absolute_err(y,yhat): 
        return np.mean((np.abs(y.sub(yhat).mean())/yhat)) 
    def rmse(y,yhat):
        return np.sqrt(sum((yhat-y)**2)/len(y))

    predictions_ARIMA = np.exp(predictions_ARIMA_log)
    plt.plot(train_weekly_resampled_data)
    plt.plot(predictions_ARIMA)

    plt.title('RMSE: %.4f |MSE: %.4f| MAE: %.4f'% (
            rmse(train_weekly_resampled_data, predictions_ARIMA), 
            mean_sqared_err(train_weekly_resampled_data, predictions_ARIMA),
            mean_absolute_err(train_weekly_resampled_data,predictions_ARIMA)))    

    plt.xlabel('Date')
    plt.legend(('Real Values', 'Predicted Values'), loc='lower right')

# forecast     
    Fcast = predictions_ARIMA.values.predict(start = '11/08/2019', end = '22/09/2019')

1 个答案:

答案 0 :(得分:0)

您的模型保存在变量model中。您应该将最后一行更改为

Fcast = model.predict(start = '11/08/2019', end = '22/09/2019')