評估 10 折交叉驗證誤差
在這個練習中,你要評估前一題中建立的回歸樹 dt 所達到的 10 折交叉驗證均方根誤差(RMSE)。
除了 dt 之外,訓練資料 X_train 與 y_train 也已提供在你的工作空間中。我們也已從 sklearn.model_selection 匯入了 cross_val_score。
請注意,因為 cross_val_score 只能回傳負的 MSE,因此其輸出需要乘上負一才會得到 MSE。接著取這些 MSE 的平均值並開平方根,即可得到交叉驗證的 RMSE。
本練習屬於課程
Machine Learning with Tree-Based Models in Python
練習說明
設定
scoring參數為'neg_mean_squared_error',計算dt的 10 折交叉驗證 MSE。由取得的 MSE 分數計算 RMSE。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Compute the array containing the 10-folds CV MSEs
MSE_CV_scores = - ____(____, ____, ____, cv=____,
____='____',
n_jobs=-1)
# Compute the 10-folds CV RMSE
RMSE_CV = (____.____)**(____)
# Print RMSE_CV
print('CV RMSE: {:.2f}'.format(RMSE_CV))