Soyeon Kim
2011-Apr-15 15:00 UTC
[R] prediction error in ROCR package when sampled y consists of only one class
Dear R users, Hi. I am using prediction function in ROCR package. y consists of two classes 0 and 1. However, since I am using cross-validation, a sampled small number of y may consist of only one class>y[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 In this case, prediction function gives an error: Error in prediction(predic, y) : Number of classes is not equal to 2. ROCR currently supports only evaluation of binary classification tasks. How can I solve this problem? Thank you, Soyeon Kim
Uwe Ligges
2011-Apr-15 15:37 UTC
[R] prediction error in ROCR package when sampled y consists of only one class
On 15.04.2011 17:00, Soyeon Kim wrote:> Dear R users, > > Hi. I am using prediction function in ROCR package. > y consists of two classes 0 and 1. > However, since I am using cross-validation, a sampled small number of > y may consist of only one class >> y > [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0If this is the output for your y, it is not even a classification task, since your y is probably numeric rather than a factor. Hence: 1. make it a factor with the desired number of levels. 2. in this case, the only useful prediction is class "0", hence you can easily special case and predict the only available class if only one is present. Best wishes, Uwe Ligges> In this case, prediction function gives an error: > Error in prediction(predic, y) : Number of classes is not equal to 2. > ROCR currently supports only evaluation of binary classification tasks. > > How can I solve this problem? > > Thank you, > Soyeon Kim > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Saeed Abu Nimeh
2011-Apr-15 21:27 UTC
[R] prediction error in ROCR package when sampled y consists of only one class
Try performing stratified sampling when doing cv. cran.r-project.org/web/packages/ipred On Fri, Apr 15, 2011 at 11:00 AM, Soyeon Kim <yunni0731 at gmail.com> wrote:> Dear R users, > > Hi. I am using prediction function in ROCR package. > y consists of two classes 0 and 1. > However, since I am using cross-validation, a sampled small number of > y may consist of only one class >>y > ?[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > In this case, prediction function gives an error: > Error in prediction(predic, y) : Number of classes is not equal to 2. > ROCR currently supports only evaluation of binary classification tasks. > > How can I solve this problem? > > Thank you, > Soyeon Kim > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Apparently Analagous Threads
- How to see a R code from a package?
- How to change leaf color by group in hclust plot or how to install A2R package in windows?
- how to get a value from a list (using paste function)?
- how to seperate " "? or how to do regression on each variable when I have multiple variables?
- Extracting slots from ROCR prediction objects