建立 Decision Tree
既然你已經把航班資料分成訓練集與測試集,就能用訓練集來訓練一個 Decision Tree 模型。
資料已提供為 flights_train 與 flights_test。
注意:模型訓練需要幾秒鐘。請耐心等候!
本練習屬於課程
使用 PySpark 的機器學習
練習說明
- 匯入用來建立 Decision Tree 分類器的類別。
- 建立分類器物件並將它擬合到訓練資料。
- 對測試資料產生預測,並查看預測結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the Decision Tree Classifier class
from pyspark.ml.____ import ____
# Create a classifier object and fit to the training data
tree = ____()
tree_model = tree.____(____)
# Create predictions for the testing data and take a look at the predictions
prediction = tree_model.____(____)
prediction.select('label', 'prediction', 'probability').show(5, False)