逐步計算 RMSE
在這個練習中,你將逐步計算最常見的模型品質量化指標之一 —— RMSE,來量化一個預先建立之模型的整體擬合優度(goodness-of-fit)。
請從已載入的 x_data 與 y_data 開始,並搭配預先定義的建模函式 model_fit_and_predict() 使用。

本練習屬於課程
Python 線性建模入門
練習說明
- 以
model_fit_and_predict(x_data, y_data)計算y_model。 - 將
y_model與y_data的差計算為residuals。 - 使用
np.sum()和np.square()計算RSS,再除以len(residuals)得到MSE。 - 對
MSE使用np.sqrt()得到RMSE,並印出所有結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Build the model and compute the residuals "model - data"
y_model = model_fit_and_predict(x_data, y_data)
residuals = ____ - ____
# Compute the RSS, MSE, and RMSE and print the results
RSS = np.____(np.____(residuals))
MSE = ____/len(residuals)
RMSE = np.____(____)
print('RMSE = {:0.2f}, MSE = {:0.2f}, RSS = {:0.2f}'.format(RMSE, MSE, RSS))