信用モデルを可視的に評価する
ここではモデルのパフォーマンスを可視化します。ROC 曲線では、X 軸と Y 軸に、すでに見た 2 つの指標(偽陽性率(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を作成し、falloutを x 軸にして 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
____ = ____(____, ____)