在 R 中的插入符训练函数中使用“ROC"度量的问题 [英] Issue using 'ROC' metric in caret train function in R

查看:44
本文介绍了在 R 中的插入符训练函数中使用“ROC"度量的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个类的不平衡数据集,因此我认为我可以使用 ROC 作为度量而不是 Accuracy 来使用 caret 包在 R 中调整我的模型(我正在尝试不同的方法,例如 rpart、rf.. 等).我认为我们可以提取概率并使用 ROC 作为决策树类型算法中的度量以及使用插入符号.我使用下面插入符号中的数据集来说明我的问题.此数据中有三个类,但为了说明目的,我重新定义并创建了两个类.我不明白为什么下面的代码会给出这个错误(当我改变方法时,我一直收到同样的错误).感谢您的帮助.

I have an imbalanced data set with two classes therefore I thought I could use ROC as a metric instead of Accuracy to tune my model in R using caret package (I am trying different methods such as rpart, rf..etc). I thought we could extract probabilities and use ROC as a metric in decision tree type algorithms as well using caret. I illustrate my problem using a data set in caret below. There are three classes in this data but I redefined and created two classes for illustration purposes. I don't understand why the below code gives this error (I keep getting the same error when I change the method). I appreciate your help.

'train.default(x, y, weights = w, ...) 中的错误:无法确定最终调整参数此外: 警告消息:1:在nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, : 重采样的性能指标中存在缺失值.2: 在 train.default(x, y, weights = w, ...) : 在聚合结果中发现缺失值'

'Error in train.default(x, y, weights = w, ...) : final tuning parameters could not be determined In addition: Warning messages: 1: In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, : There were missing values in resampled performance measures. 2: In train.default(x, y, weights = w, ...) : missing values found in aggregated results'

library(caret) 
data(iris)

iris$Species=as.character(iris$Species)
iris$Species[which(iris$Species=='virginica')]='versicolor'
iris$Species=as.factor(iris$Species)

fitControl <- trainControl(method = "cv",number=5,classProbs = TRUE,summaryFunction = twoClassSummary)

RF=train(Species ~ ., data = iris, method="rpart",metric="ROC", trControl=fitControl)

推荐答案

你的 r 和 caret 版本可能有问题.当您更新插入符包时,请确保您的 r 版本也保持更新.

It might be a problem with your versions of r and caret. When you update your caret package, make sure that your version of r is kept updated as well.

我之前遇到过这个错误,更新 r 版本解决了它.

I had this error before and updating r version solved it.

这篇关于在 R 中的插入符训练函数中使用“ROC"度量的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆