開始使用免費開始

比較模型報告

你已經使用了羅吉斯迴歸模型與梯度提升樹。現在該比較這兩者,決定要用哪個模型來做最終預測。

比較不同模型在「違約機率」預測能力的第一步,最簡單的做法之一,就是查看 classification_report() 的評估指標。這能讓你將各模型的多種評分指標並排檢視。由於資料與模型通常是不平衡的,違約樣本很少,因此此刻請先聚焦在「違約」這個類別的指標。

已訓練的模型 clf_logisticclf_gbt 已載入工作區,並提供其預測結果 preds_df_lrpreds_df_gbt。兩者都使用了 0.4 的閾值(cutoff)。測試集 y_test 也可使用。

本練習屬於課程

以 Python 進行信用風險建模

檢視課程

練習說明

  • 列印羅吉斯迴歸預測的 classification_report()
  • 列印梯度提升樹預測的 classification_report()
  • 使用 precision_recall_fscore_support(),列印羅吉斯迴歸的 F-1 分數之 macro average
  • 使用 precision_recall_fscore_support(),列印梯度提升樹的 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])
編輯並執行程式碼