开始使用免费开始使用

给定阈值下比较链接函数

在最后这个练习中,您将分别使用三种链接函数(logit、probit 和 cloglog)来拟合模型,在测试集上进行预测,按给定阈值将预测结果分类为相应分组(违约 与 非违约),构建混淆矩阵,并计算在该阈值下每个模型的准确率与灵敏度。到这里为止,您已经学到了很多!最后,您还将尝试在给定阈值下,找出准确率表现最好的模型。

需要注意的是,这些模型之间的差异通常会非常小,而且结果依赖于所选阈值。观测到的结果(违约 与 非违约)已存储在控制台中的 true_val

本练习是课程的一部分

R 中的信用风险建模

查看课程

练习说明

  • 分别使用 logitprobitcloglog 链接函数拟合 3 个逻辑回归模型。部分代码已给出。使用 ageemp_catir_catloan_amnt 作为自变量。
  • 使用 test_set 为所有模型生成预测。
  • 使用 14% 作为阈值,对每个模型进行分类预测,以便评估其性能。
  • 为这三个模型分别构建混淆矩阵。
  • 最后,计算三个模型的分类准确率。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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 <- 
编辑并运行代码