Re: [R] prediction error in ROCR package when sampled y consists of only one class

From: Uwe Ligges <ligges_at_statistik.tu-dortmund.de>
Date: Fri, 15 Apr 2011 17:37:31 +0200

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 0

If 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.



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. Received on Fri 15 Apr 2011 - 15:41:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 15 Apr 2011 - 16:00:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive