我使用R中的randomForest包创建一个模型,将病例分类为疾病(1)或无疾病(0):
classify_BV_100t <- randomForest(bv.disease~., data=RF_input_BV_clean, ntree = 100, localImp = TRUE)
print(classify_BV_100t)
Call:
randomForest(formula = bv.disease ~ ., data = RF_input_BV_clean, ntree = 100, localImp = TRUE)
Type of random forest: classification
Number of trees: 100
No. of variables tried at each split: 53
OOB estimate of error rate: 8.04%
Confusion matrix:
0 1 class.error
0 510 7 0.01353965
1 39 16 0.70909091
我的混淆矩阵显示该模型擅长将0分类(无疾病),但很难分类为1(疾病)。
但是,当我绘制ROC图时,它给人的印象是该模型相当不错。
这是我绘制ROC的2种不同方法:
library(pROC)
rf.roc<-roc(RF_input_BV_clean$bv.disease, classify_BV_100t$votes[,2])
plot(rf.roc)
auc(rf.roc)
(在R中使用插入符号进行训练后,如何在ROC下使用ROC和AUC?)
library(ROCR)
predictions <- as.vector(classify_BV_100t$votes[,2])
pred <- prediction(predictions, RF_input_BV_clean$bv.disease)
perf_AUC <- performance(pred,"auc") #Calculate the AUC value
AUC <- [email protected][[1]]
perf_ROC <- performance(pred,"tpr","fpr") #plot the actual ROC curve
plot(perf_ROC, main="ROC plot")
text(0.5,0.5,paste("AUC = ",format(AUC, digits=5, scientific=FALSE)))
这些是1和2中的ROC图:
两种方法的AUC均为0.8621593。
有谁知道为什么随机森林混淆矩阵的结果似乎不会与ROC / AUC相加?
我不认为您的ROC图有任何问题,并且您对差异的评估是正确的。
高AUC值是真实负率很高的产物。ROC考虑了敏感性;在很大程度上衡量了真正的积极价值和特异性;真实负值的度量。由于您的特异性很高,因此该指标有效地承载了模型的较低灵敏度值,这使您的AUC保持相对较高。是的,它的AUC很高,但是正如您所提到的,该模型仅擅长预测负数。
我建议您计算其他指标(敏感性,特异性,真阳性率,假阳性率...),并在评估模型时评估所有这些指标的组合。AUC是一种质量指标,但它背后还有更多其他指标,这意味着更多。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句