[英]Plot ROC curve with pROC R
I build a text classifier with randomForest, so to evaluate it I try to create a ROC curve with pROC pâckage . 我使用randomForest构建文本分类器,因此要对其进行评估,我尝试使用pROCpâckage创建ROC曲线。
Here the code : 这里的代码:
ndsi.forest <- randomForest(tf.idf[train.index, ], as.factor(train$Note.Reco[train.index]), ntree = 100)
#predict with test data
ndsi.pred <-predict(ndsi.forest, newdata = tf.idf[test.index, ], response = 'class')
pred <- data.frame(ndsi.pred)
result <- data.frame(id = Data_clean$id[test.index], sentiment = pred[ , ])
##"ROC curve"
multiclass.roc(result$sentiment, test$Note.Reco)
I was wondering if is teher a way to create the plot? 我想知道是否是一种创建情节的方法? ROC plot with pROC package?
用pROC包进行ROC图?
I try with this code : 我尝试使用以下代码:
roc(test$Note.Reco, result$sentiment, levels = c(1,2,3,4,5,6,7,8,9,10))
But I get this error : 但是我得到这个错误:
Error in roc.default(test$Note.Reco, result$sentiment, levels = c(1, 2, :
'levels' argument must have length 2
thank you in advance 先感谢您
As far as I have understood, you have a multiclass response variable (corresponding to 10 different groups). 据我了解,您有一个多类响应变量 (对应于10个不同的组)。
The ROC - curve is defined for the classification of two groups, so what multiclass makes is to compute the classification for " one group against the rest ". ROC-曲线是为两组的分类定义的,因此多类分类是针对“ 一组相对于其余组 ”计算分类。
multiclass.roc
function doesn't allow you to represent the curves, but understanding what it does, you can: multiclass.roc
函数不允许您表示曲线,但是了解它的作用后,您可以:
1) Consider as many roc curves as groups you have. 1)考虑尽可能多的roc曲线。 That is, the ROC - curve for the classification of:
即,ROC-曲线用于分类:
You can do that with the roc
function. 您可以使用
roc
函数来做到这一点。 The only thing you need is to redefine the response vector with 1 for the individuals belonging to the group i and a 0 for the rest of individuals. 您唯一需要做的就是重新定义响应向量,其中i属于第i组,其余为0。 Save each
roc
object with a differnt name. 用不同的名称保存每个
roc
对象。
2) To represent all the curves, just use plot
function for each of the curves adding plot(..., add=T)
to all of them but the first. 2)要表示所有曲线,只需对每条曲线使用
plot
函数,将plot(..., add=T)
到除第一条曲线之外的所有曲线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.