최적 모델 개발 및 테스트
3장에서는 다음 파라미터를 사용하면 더 나은 모델을 만들 수 있다는 것을 확인했어요:
max_depth = 8,min_samples_leaf = 150,class_weight = "balanced"
이번 장에서는 일부 특성이 영향이 미미하다는 점을 알게 되었고, 소수의 핵심 특성만으로도 정확한 예측이 가능하다는 사실을 확인했어요. 이에 따라 학습/테스트 세트를 업데이트하여 features_train_selected와 features_test_selected 변수를 만들었습니다.
이 정보를 바탕으로 이제 직원 이직을 예측하는 최적 모델을 개발하고, 적절한 지표로 성능을 평가해 보겠습니다.
작업 공간에는 features_train_selected와 features_test_selected 변수가 준비되어 있으며, recall_score와 roc_auc_score 함수도 이미 임포트되어 있습니다.
이 연습은 강의의 일부입니다
HR Analytics: Python으로 직원 이탈 예측하기
연습 안내
- 설명에 제공된 파라미터로 최적 모델을 초기화하세요.
- 학습 세트의 선택된 특성만 사용해 모델을 학습(fit)하세요.
- 테스트 세트의 선택된 특성에 기반해 예측을 수행하세요.
- 모델의 정확도(accuracy), 재현율(recall), ROC/AUC 점수를 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Initialize the best model using parameters provided in description
model_best = DecisionTreeClassifier(____=____, ____=____, ____=____, random_state=42)
# Fit the model using only selected features from training set: done
model_best.fit(____, target_train)
# Make prediction based on selected list of features from test set
prediction_best = model_best.____(____)
# Print the general accuracy of the model_best
print(____.score(features_test_selected, target_test) * 100)
# Print the recall score of the model predictions
print(____(target_test, prediction_best) * 100)
# Print the ROC/AUC score of the model predictions
print(roc_auc_score(target_test, ____) * 100)