檢查 out-of-bag 分數
現在來檢查前一個練習中模型的 out-of-bag 分數。
到目前為止,你用的是 F1 分數來衡量效能。不過在這個練習中,請改用 accuracy 分數,這樣就能更容易和 out-of-bag 分數比較。
前一個練習的決策樹分類器 clf_dt 已經在你的工作環境中可用。
pokemon 資料集已經為你載入,並切分為訓練集與測試集。此外,決策樹分類器已經訓練完成,且以 clf_dt 提供給你作為基礎估計器使用。
本練習屬於課程
Python 的 Ensemble 方法
練習說明
- 以決策樹作為基礎估計器,並使用 21 個估計器來建立 bagging 分類器。這次請透過為參數
oob_score指定引數,啟用 out-of-bag 分數。 - 列印分類器的 out-of-bag 分數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Build and train the bagging classifier
clf_bag = ____(
____,
____,
____,
random_state=500)
clf_bag.fit(X_train, y_train)
# Print the out-of-bag score
print('OOB-Score: {:.3f}'.format(____))
# Evaluate the performance on the test set to compare
pred = clf_bag.predict(X_test)
print('Accuracy: {:.3f}'.format(accuracy_score(y_test, pred)))