我已经在Rstudio中建立了一个用于流失预测的二进制逻辑回归。由于此模型使用的数据不平衡,因此我还包括了权重。然后,我试图通过尝试和错误来找到最佳截止点,但是为了完成我的研究,我必须结合ROC曲线来找到最佳截止点。下面我提供了用于构建模型的脚本(fit2)。权重存储在“W”中。这表明,错误识别流失的成本是错误识别非流失的成本的14倍。
#CH1 logistic regression
library(caret)
W = 14
lvl = levels(trainingset$CH1)
print(lvl)
#if positive we give it the defined weight, otherwise set it to 1
fit_wts = ifelse(trainingset$CH1==lvl[2],W,1)
fit2 = glm(CH1 ~ RET + ORD + LVB + REVA + OPEN + REV2KF + CAL + PSIZEF + COM_P_C + PEN + SHOP, data = trainingset, weight=fit_wts, family=binomial(link='logit'))
# we test it on the test set
predlog1 = ifelse(predict(fit2,testset,type="response")>0.5,lvl[2],lvl[1])
predlog1 = factor(predlog1,levels=lvl)
predlog1
confusionMatrix(pred,testset$CH1,positive=lvl[2])对于这项研究,我还使用pROC包构建了决策树的ROC曲线。然而,当然,相同的脚本对逻辑回归并不是相同的。我已经使用下面的脚本创建了逻辑回归的ROC曲线。
prob=predict(fit2, testset, type=c("response"))
testset$prob=prob
library(pROC)
g <- roc(CH1 ~ prob, data = testset, )
g
plot(g)这导致了下面的ROC曲线。

如何获得ROC曲线的最佳截止值?
发布于 2020-03-23 16:09:28
获得“最佳”截止值完全独立于模型的类型,因此您可以像使用pROC的任何其他类型的模型一样获得它。使用coords函数:
coords(g, "best", transpose = FALSE)或者直接在绘图上:
plot(g, print.thres=TRUE)现在,上述方法简单地最大化了敏感性和特异性的总和。这通常太简单了,您可能需要一个适合您的用例的“最佳”的清晰定义。这在很大程度上超出了这个问题的范围,但是作为一个起点,您应该看看Best Thresholds section of the documentation of the coords function中的一些基本选项。
https://stackoverflow.com/questions/60799990
复制相似问题