時間序列 - 逐步驗證
在時間序列建模中,隨著時間的推移,預測會變得越來越不準確,因此一種更實際的方法是在獲得實際資料後用這些資料重新訓練模型,以便進行進一步的預測。由於訓練統計模型不會耗費大量時間,所以逐步驗證是最受青睞的解決方案,它可以得到最準確的結果。
讓我們對自己的資料應用一步一步的逐步驗證,並將它與我們之前獲得的結果進行比較。
In [333]
prediction = [] data = train.values for t In test.values: model = (ExponentialSmoothing(data).fit()) y = model.predict() prediction.append(y[0]) data = numpy.append(data, t)
In [335]
test_ = pandas.DataFrame(test) test_['predictionswf'] = prediction
In [341]
plt.plot(test_['T']) plt.plot(test_.predictionswf, '--') plt.show()
In [340]
error = sqrt(metrics.mean_squared_error(test.values,prediction))
print ('Test RMSE for Triple Exponential Smoothing with Walk-Forward Validation: ', error)
Test RMSE for Triple Exponential Smoothing with Walk-Forward Validation: 11.787532205759442
我們可以看到,我們的模型現在表現得要好得多。實際上,它緊密地遵循了趨勢,在圖中,預測值與實際值完全重疊。你可以在 ARIMA 模型上嘗試應用逐步驗證。
廣告