简体   繁体   English

如何使用pROC或ROCR包在R中根据预测的类概率计算ROC曲线下的面积?

[英]How to compute area under ROC curve from predicted class probabilities, in R using pROC or ROCR package?

I have used caret library to compute class probabilities and predictions for a binary classification problem, using 10-fold cross validation and 5 times repetition. 我使用插入库来计算二元分类问题的类概率和预测,使用10倍交叉验证和5次重复。

Now I have TRUE (observed values for each data point) values, PREDICTED (by an algorithm) values, Class 0 probabilities and Class 1 probabilities which were used by an algorithm to predict class label. 现在我有TRUE (每个数据点的观测值)值, PREDICTED (通过算法)值, 0级概率1类概率 ,它们被算法用来预测类标签。

Now how can I create an roc object using either ROCR or pROC library and then calculate auc value? 现在我如何使用ROCRpROC库创建一个roc对象,然后计算auc值?

Assume that I have all these values stored in predictions dataframe. 假设我将所有这些值存储在predictions数据帧中。 eg predictions$pred and predictions$obs are the predicted and true values respectively, and so on... 例如predictions$predpredictions$obs分别是预测值和真值,依此类推......

Since you did not provide a reproducible example, I'm assuming you have a binary classification problem and you predict on Class that are either Good or Bad . 由于您没有提供可重现的示例,我假设您有二进制分类问题,并且您在Class上预测GoodBad

predictions <- predict(object=model, test[,predictors], type='prob')

You can do: 你可以做:

> pROC::roc(ifelse(test[,"Class"] == "Good", 1, 0), predictions[[2]])$auc
# Area under the curve: 0.8905

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM