Gradient-Boosted Trees로 지연 항공편 예측
이전에는 Decision Tree를 사용해 지연될 가능성이 있는 항공편을 분류하는 모델을 만들었어요. 이번 연습에서는 Decision Tree 모델과 Gradient-Boosted Trees 모델을 비교해 볼 거예요.
항공편 데이터는 무작위로 flights_train과 flights_test로 분할되어 있어요.
이 연습은 강의의 일부입니다
PySpark로 하는 Machine Learning
연습 안내
- Decision Tree와 Gradient-Boosted Tree 분류기를 만들 때 필요한 클래스를 import하세요.
- Decision Tree와 Gradient-Boosted Tree 분류기를 생성하고, 학습 데이터로 학습시키세요.
- evaluator를 생성하고, 두 분류기에 대해 테스트 데이터의 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.____)