你的第一個 AdaBoost 模型
在前一個課程中,你建立了用來預測電影對數營收的模型。你先從簡單的線性迴歸開始,得到 RMSE 為 7.34。接著,你嘗試使用一次 boosting 來改進,將 RMSE 降到 7.28。
在這個練習中,你將建立第一個 AdaBoost 模型——AdaBoostRegressor——試著把效能再往上提升。
movies 資料集已載入並分割為訓練集與測試集。這裡你會使用 'budget' 和 'popularity' 這兩個特徵,且已替你先用 sklearn.preprocessing 模組中的 StandardScaler() 做過標準化。
本練習屬於課程
Python 的 Ensemble 方法
練習說明
- 實例化預設的線性迴歸模型。
- 建立並擬合一個
AdaBoostRegressor,使用線性迴歸作為基底模型,並設定12個估計器。 - 在測試集上計算預測值。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Instantiate the default linear regression model
reg_lm = ____
# Build and fit an AdaBoost regressor
reg_ada = ____(____, ____, random_state=500)
reg_ada.fit(X_train, y_train)
# Calculate the predictions on the test set
pred = ____
# Evaluate the performance using the RMSE
rmse = np.sqrt(mean_squared_error(y_test, pred))
print('RMSE: {:.3f}'.format(rmse))