開始使用免費開始

評估 RF 迴歸器

現在你要評估上一個練習中訓練好的隨機森林迴歸器 rf 在測試集上的 RMSE。

資料集已為你處理好,並切分為 80% 訓練集與 20% 測試集。特徵矩陣 X_test 與陣列 y_test 已可在你的工作環境中使用。此外,我們也已載入你在上一個練習訓練的模型 rf

本練習屬於課程

Machine Learning with Tree-Based Models in Python

檢視課程

練習說明

  • sklearn.metrics 匯入 mean_squared_error,並命名為 MSE
  • 預測測試集標籤,將結果指定給 y_pred
  • 計算測試集的 RMSE,將結果指定給 rmse_test

動手互動練習

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

# Import mean_squared_error as MSE
from ____.____ import ____ as ____

# Predict the test set labels
y_pred = ____.____(____)

# Evaluate the test set RMSE
rmse_test = ____

# Print rmse_test
print('Test set RMSE of rf: {:.2f}'.format(rmse_test))
編輯並執行程式碼