開始使用免費開始

逐步計算 RMSE

在這個練習中,你將逐步計算最常見的模型品質量化指標之一 —— RMSE,來量化一個預先建立之模型的整體擬合優度(goodness-of-fit)。

請從已載入的 x_datay_data 開始,並搭配預先定義的建模函式 model_fit_and_predict() 使用。

本練習屬於課程

Python 線性建模入門

檢視課程

練習說明

  • model_fit_and_predict(x_data, y_data) 計算 y_model
  • y_modely_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))
編輯並執行程式碼