開始使用免費開始

還能再精簡模型嗎?

刪除變數 loan_amnt 後,AUC 竟然還能提升到 0.6548!得到的模型為:

log_4_remove_amnt <- glm(loan_status ~ grade + annual_inc + emp_cat, family = binomial, data = training_set) 

有沒有可能把這個羅吉斯迴歸模型再精簡到只剩兩個變數,而且不降低 AUC?這個練習就帶你試試看!

本練習屬於課程

R 的信用風險建模

檢視課程

練習說明

  • 依序在模型 log_4_remove_amnt 中一次刪除一個變數。記得要使用預設的連結函式(logit)。
  • 使用 predict() 為你建立的每個模型產生違約機率的預測。
  • 針對三個模型各自計算 AUC:test_set$loan_status 作為第一個引數,對應模型的預測作為第二個引數。
  • 在工作區中為 AUC 最高的模型繪製 ROC 曲線,使用 plot(roc()),其中 roc() 的內容與 AUC 最高時呼叫 auc() 的內容相同。請注意,相較於 log_4_remove_amnt,AUC 也有可能已無法再提升。若此模型帶來最高 AUC,其預測已載入為 pred_4_remove_amnt

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Build three models each time deleting one variable in log_4_remove_amnt
log_5_remove_grade <- glm(loan_status ~ annual_inc + emp_cat, family = binomial, data = training_set) 
log_5_remove_inc <- 
log_5_remove_emp <- 

# Make PD-predictions for each of the models
pred_5_remove_grade <- predict(log_5_remove_grade, newdata = test_set, type = "response")
pred_5_remove_inc <-
pred_5_remove_emp <-

# Compute the AUCs



# Plot the ROC-curve for the best model here
編輯並執行程式碼