신용 모델의 성능을 시각적으로 평가하기
이제 모델의 성능을 시각화해 보려고 해요. ROC 차트에서 X축과 Y축은 이미 살펴본 두 가지 지표인 위양성률(fall-out)과 진양성률(sensitivity)이에요.
다음 코드를 사용하면 모델 성능의 ROC 차트를 만들 수 있어요:
fallout, sensitivity, thresholds = roc_curve(y_test, prob_default)
plt.plot(fallout, sensitivity)
AUC 점수를 계산하려면 roc_auc_score()를 사용해요.
신용 데이터 cr_loan_prep과 X_test, y_test 데이터 세트가 작업 공간에 모두 로드되어 있어요. 학습된 LogisticRegression() 모델 clf_logistic도 작업 공간에 로드되어 있어요.
이 연습은 강의의 일부입니다
Python으로 배우는 신용 리스크 모델링
연습 안내
- 부도 확률 예측값을 만들어
preds에 저장하세요. X와y테스트 세트에 대해 모델의 정확도를 출력하세요.- 테스트 데이터와 부도 확률을 사용해
roc_curve()로fallout과sensitivity를 만든 다음, x축에fallout을 두고 ROC 곡선 그래프를 그리세요. - 테스트 데이터와 부도 확률을 사용해 모델의 AUC를 계산하고
auc에 저장하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Create predictions and store them in a variable
____ = clf_logistic.____(____)
# Print the accuracy score the model
print(clf_logistic.____(____, ____))
# Plot the ROC curve of the probabilities of default
prob_default = preds[:, 1]
fallout, sensitivity, thresholds = ____(____, ____)
plt.plot(fallout, sensitivity, color = 'darkorange')
plt.plot([0, 1], [0, 1], linestyle='--')
plt.____()
# Compute the AUC and store it in a variable
____ = ____(____, ____)