以 MAE、MSE 進行回溯測試
在這個練習中,你將透過回溯測試來評估模型效能。樣本外的預測準確度將以計算 MSE 與 MAE 進行評估。
你可以使用 sklearn.metrics 套件中的預先定義函式,輕鬆估計預測誤差 MSE 與 MAE。實際變異與預測變異已分別預先載入於 actual_var 與 forecast_var。
本練習屬於課程
Python 中的 GARCH 模型
練習說明
- 在
evaluate()中,呼叫sklean.metrics對應的函式來計算 MAE。 - 在
evaluate()中,呼叫sklean.metrics對應的函式來計算 MSE。 - 將變數傳入
evaluate(),以執行回溯測試。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
def evaluate(observation, forecast):
# Call sklearn function to calculate MAE
mae = ____(observation, forecast)
print('Mean Absolute Error (MAE): {:.3g}'.format(mae))
# Call sklearn function to calculate MSE
mse = ____(observation, forecast)
print('Mean Squared Error (MSE): {:.3g}'.format(mse))
return mae, mse
# Backtest model with MAE, MSE
evaluate(____, ____)