O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using arbitrary class labels

Unlike in the preceding example, we might have arbitrary class labels for success and failure. The rocr-example-2.csv file has buyer and non-buyer as the class labels, with buyer representing the success case.

In this case, we need to explicitly indicate the failure and success labels by passing in a vector with the failure case as the first element:

> dat <- read.csv("roc-example-2.csv") 
> pred <- prediction(dat$prob, dat$class, label.ordering = c("non-buyer", "buyer")) 
> perf <- performance(pred, "tpr", "fpr") 
> plot(perf) 
> lines( par()$usr[1:2], par()$usr[3:4] ) 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required