使用 Gradient-Boosted Trees 預測延誤航班
你先前已使用決策樹建立過一個用來判斷航班是否可能延誤的分類器。這個練習要你比較決策樹模型與 Gradient-Boosted Trees 模型。
航班資料已隨機切分為 flights_train 與 flights_test。
本練習屬於課程
使用 PySpark 的機器學習
練習說明
- 匯入建立決策樹與 Gradient-Boosted Tree 分類器所需的類別。
- 建立決策樹與 Gradient-Boosted Tree 分類器,並在訓練資料上進行訓練。
- 建立評估器,並在測試資料上計算兩個分類器的 AUC。哪個模型表現較佳?
- 對於 Gradient-Boosted Tree 分類器,印出樹的數量以及各特徵的相對重要性。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the classes required
from pyspark.ml.____ import ____, ____
from pyspark.ml.evaluation import BinaryClassificationEvaluator
# Create model objects and train on training data
tree = ____().____(____)
gbt = ____().____(____)
# Compare AUC on testing data
evaluator = ____()
print(evaluator.____(tree.____(____)))
print(evaluator.____(gbt.____(____)))
# Find the number of trees and the relative importance of features
print(gbt.____)
print(gbt.____)