问题描述
我在 R 中训练了一个带有线性核的 SVM 来对患有疾病的患者进行分类,使用 predict() 函数使用 SVM 模型在测试集上生成预测概率,然后使用 roc() 函数从pROC 库。我还使用 coords() 来计算使用 Youden 指数的最佳切点。 coords() 返回的切点为 0.8489392,特异性为 0.6250000,敏感性为 0.7954545。
当我尝试使用在此分界点进行的预测生成混淆矩阵时,我得到 0.20455 的灵敏度和 0.37500 的特异性,但无法弄清楚为什么它们与 coords() 报告的灵敏度和特异性不匹配。
这是几个模型中唯一一个两个函数报告的灵敏度和特异性不匹配的模型。
代码如下:
svm_linear <- train(ercp_chole ~ stone_any_modality + age + peak_pre_bili + max_cbd_dia_any,data = chole_training,method = "svmLinear",trControl = trainControl(method = "repeatedcv",number = 10,repeats = 3,classProbs=TRUE,summaryFunction=twoClassSummary),na.action = na.exclude,preProcess = c("center","scale"),metric = "ROC",tuneLength = 10
)
pprob_svm_linear <- predict(svm_linear,chole_testing,type="prob")
svm_linear_roc <- roc(chole_testing$ercp_chole,pprob_svm_linear[,2],auc=TRUE)
coords(svm_linear_roc,"best","threshold",transpose=TRUE,best.method="youden")
confusionMatrix(factor( ifelse(pprob_svm_linear[,"chole_pos"] > 0.8489392,"chole_pos","chole_neg") ),chole_testing$ercp_chole,positive="chole_pos")
调用 roc() 的结果:
Setting levels: control = chole_neg,case = chole_pos
Setting direction: controls > cases
调用 coords() 的结果:
threshold specificity sensitivity
0.8489392 0.6250000 0.7954545
confusionMatrix() 的调用结果:
Confusion Matrix and Statistics
Reference
Prediction chole_neg chole_pos
chole_neg 3 35
chole_pos 5 9
Accuracy : 0.2308
95% CI : (0.1253,0.3684)
No Information Rate : 0.8462
P-Value [Acc > NIR] : 1
Kappa : -0.1659
Mcnemar's Test P-Value : 4.533e-06
Sensitivity : 0.20455
Specificity : 0.37500
Pos Pred Value : 0.64286
Neg Pred Value : 0.07895
Prevalence : 0.84615
Detection Rate : 0.17308
Detection Prevalence : 0.26923
Balanced Accuracy : 0.28977
'Positive' Class : chole_pos
任何帮助将不胜感激!
提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)