受限模型的樣本內擬合
你已經計算 logitModelFull 的準確率。對所有模型候選都這麼做非常重要。
因此,logitModelNew 已經定義並存在於你的環境中。
在彼此比較不同模型的數值時:如果不同模型的準確率相同,請一律選擇解釋變數較少的模型。
本練習屬於課程
R 的行銷分析機器學習
練習說明
針對新模型,重做上一個練習的相同步驟。
使用
predict()取得每位客戶發生違約的機率。接著用相同的分類閾值 0.5 計算混淆矩陣。請注意,
SDMTools已無法從 CRAN 下載。請改用remotes::install_version("SDMTools", "1.1-221.2")安裝。計算受限模型的準確率,並與完整模型的準確率比較。接下來只繼續使用表現較佳的模型進行分析。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Calculate the accuracy for 'logitModelNew'
# Make prediction
defaultData$predNew <- predict(logitModelNew, type = ___, na.action = ___)
# Construct the in-sample confusion matrix
confMatrixModelNew <- confusion.matrix(defaultData$___,defaultData$___, threshold = ___)
confMatrixModelNew
# Calculate the accuracy...
accuracyNew <- sum(diag(___)) / ___(___)
accuracyNew
# and compare it to the full model's accuracy
accuracyFull