始める無料で始める

与えたカットオフに対するリンク関数の比較

この最後の演習では、3つのリンク関数(logit、probit、cloglog)それぞれでモデルを当てはめ、テストデータに対して予測を行い、与えられたカットオフに基づいて予測を適切なグループ(延滞 vs 非延滞)に分類し、混同行列を作成し、各モデルの精度(accuracy)と感度(sensitivity)を計算します。ここまで本当に多くのことを学んできましたね。最後に、与えられたカットオフのもとで精度が最も高いモデルを見つけてみましょう!

モデル間の差は一般にごく小さく、結果は選んだカットオフ値に依存することを覚えておいてください。観測された結果(延滞 vs 非延滞)は、コンソール内の true_val に保存されています。

この演習はコースの一部です

R で学ぶクレジットリスク・モデリング

コースを見る

演習の手順

  • リンクをそれぞれ logitprobitcloglog として、3つのロジスティック回帰モデルを当てはめてください。コードの一部は用意されています。予測変数には ageemp_catir_catloan_amnt を使います。
  • すべてのモデルについて、test_set を用いて予測を作成します。
  • 3つのモデルの性能を評価できるよう、カットオフ値は 14% を用いて予測を分類します。
  • 3つのモデルそれぞれについて混同行列を作成します。
  • 最後に、3つすべてのモデルの分類精度を計算してください。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Fit the logit, probit and cloglog-link logistic regression models
log_model_logit <- glm(loan_status ~ age + emp_cat + ir_cat + loan_amnt,
                       family = binomial(link = logit), data = training_set)
log_model_probit <- 

log_model_cloglog <-  
  
# Make predictions for all models using the test set
predictions_logit <- predict(log_model_logit, newdata = test_set, type = "response")
predictions_probit <- 
predictions_cloglog <- 
  
# Use a cut-off of 14% to make binary predictions-vectors
cutoff <- 0.14
class_pred_logit <- ifelse(predictions_logit > cutoff, 1, 0)
class_pred_probit <- 
class_pred_cloglog <- 
  
# Make a confusion matrix for the three models
tab_class_logit <- table(true_val,class_pred_logit)
tab_class_probit <- 
tab_class_cloglog <- 
  
# Compute the classification accuracy for all three models
acc_logit <- sum(diag(tab_class_logit)) / nrow(test_set)
acc_probit <- 
acc_cloglog <- 
コードを編集して実行