整合所學
好了,該把你到目前為止學到的內容全部串在一起了!在本課程的最後一個練習中,你會把前面練習的成果整合成一個端到端的 XGBoost pipeline,進一步鞏固你對 XGBoost 中前處理與 pipeline 的理解。
你在前 3 個練習中完成的資料前處理與 pipeline 設定都已預先載入。你的任務是執行隨機搜尋,並找出最佳的超參數。
本練習屬於課程
使用 XGBoost 的極端梯度提升
練習說明
- 設定參數網格以調整
'clf__learning_rate'(從0.05到1,步長0.05)、'clf__max_depth'(從3到10,步長1)、以及'clf__n_estimators'(從50到200,步長50)。 - 以你的
pipeline作為 estimator,執行 2 折的RandomizedSearchCV,並將n_iter設為2。評估指標使用"roc_auc",且將verbose設為1以獲得更詳細的輸出。將結果儲存到randomized_roc_auc。 - 將
randomized_roc_auc擬合到X和y。 - 計算
randomized_roc_auc的最佳分數與最佳估計器。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create the parameter grid
gbm_param_grid = {
'____': ____(____, ____, ____),
'____': ____(____, ____, ____),
'____': ____(____, ____, ____)
}
# Perform RandomizedSearchCV
randomized_roc_auc = ____
# Fit the estimator
____
# Compute metrics
print(____)
print(____)