開始使用免費開始

平均絕對誤差

在用模型做預測之前,你當然會想先了解預測的準確度。平均絕對誤差(MAE)是一個不錯的指標。它是你的預測值與真實值之間差異的平均值。

在這個練習中,你將為配適到地震時間序列的 ARMA(1,1) 模型計算 MAE。

numpy 已以 np 匯入到你的環境中,地震時間序列已以 earthquake 提供給你使用。

本練習屬於課程

Python 中的 ARIMA 模型

檢視課程

練習說明

  • 使用 np 的函式計算 results 物件 .resid 屬性的平均絕對誤差(MAE)。
  • 列印 MAE。
  • 使用 DataFrame 的 .plot() 方法(不帶參數)繪製 earthquake 時間序列。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Fit model
model = ARIMA(earthquake, order=(1,0,1))
results = model.fit()

# Calculate the mean absolute error from residuals
mae = ____

# Print mean absolute error
print(____)

# Make plot of time series for comparison
____
plt.show()
編輯並執行程式碼