Time Series 简明教程
Time Series - Walk Forward Validation
在时间序列建模中,随着时间的推移,预测会变得越来越不准确,因此根据实际数据重新训练模型是一种更为现实的方法,因为它可以用于进一步预测。由于统计模型的训练并不耗时,因此按步进验证是获得最准确结果的最优解决方案。
In time series modelling, the predictions over time become less and less accurate and hence it is a more realistic approach to re-train the model with actual data as it gets available for further predictions. Since training of statistical models are not time consuming, walk-forward validation is the most preferred solution to get most accurate results.
我们对数据应用一步按步进验证,并将其与我们之前获得的结果进行比较。
Let us apply one step walk forward validation on our data and compare it with the results we got earlier.
[333] 中:
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)
[335] 中:
In [335]:
test_ = pandas.DataFrame(test)
test_['predictionswf'] = prediction
[341] 中:
In [341]:
plt.plot(test_['T'])
plt.plot(test_.predictionswf, '--')
plt.show()
[340] 中:
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 模型应用按步进验证。
We can see that our model performs significantly better now. In fact, the trend is followed so closely that on the plot predictions are overlapping with the actual values. You can try applying walk-forward validation on ARIMA models too.