モデルレポートの比較
すでにロジスティック回帰モデルとGradient Boosted Treesを使いました。どちらを最終予測に使うか比較してみましょう。
異なるモデルのデフォルト確率を予測する力を手早く比較するには、classification_report() の指標を見るのが簡単です。これにより、各モデルについて複数の評価指標を横並びで確認できます。データやモデルは通常、デフォルト件数が少なく不均衡になりがちなので、まずはデフォルトクラスの指標に注目してください。
学習済みモデル clf_logistic と clf_gbt、およびそれぞれの予測 preds_df_lr と preds_df_gbt はワークスペースに読み込まれています。両方にカットオフ 0.4 を使用しています。テストデータ y_test も利用可能です。
この演習はコースの一部です
Pythonで学ぶクレジットリスクモデリング
演習の手順
- ロジスティック回帰の予測に対して
classification_report()を出力してください。 - Gradient Boosted Tree の予測に対して
classification_report()を出力してください。 precision_recall_fscore_support()を使って、ロジスティック回帰の F-1 スコアのmacro averageを出力してください。precision_recall_fscore_support()を使って、Gradient Boosted Tree の F-1 スコアのmacro averageを出力してください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Print the logistic regression classification report
target_names = ['Non-Default', 'Default']
print(____(____, ____['loan_status'], target_names=target_names))
# Print the gradient boosted tree classification report
print(____(____, ____['loan_status'], target_names=target_names))
# Print the default F-1 scores for the logistic regression
print(____(____,____['loan_status'], average = 'macro')[2])
# Print the default F-1 scores for the gradient boosted tree
print(____(____,____['loan_status'], average = 'macro')[2])