Questions tagged [roc]

ROC (Receiver Operating Characteristic) curve is a graphical plot comparing the true positive and false positive rates of a classifier as its discrimination threshold is varied.

Receiver Operating Characteristic curve, or ROC curve, is a graphical depiction of classifier performance that shows the trade-off between increasing true positive rates (on the vertical axis) and increasing false positive rates (on the horizontal axis) as the discrimination threshold of the classifier is varied.

The true positive rate, defined as is the the fraction of true positives out of the positives, is also called the sensitivity or recall. The false positive rate, defined as the fraction of false positives out of the negatives, is equivalent to 1 - sensitivity.

In its original form, the ROC curve was used to summarize performance of a binary classification task, although it can be extended for use in multi-class problems.

A classifier performing at chance is expected to have true positive and false positive rates that are equal, producing a diagonal line. Classifiers that exceed chance produce a curve above this diagonal. The area under the curve (or AUC) is commonly used as a summary of the ROC curve and as a measure of classifier performance. The AUC is equal to the probability that a classifier will rank a randomly chosen positive case higher than a randomly chosen negative one. This is equivalent to the Wilcoxon test of ranks.

ROC curves enable visualizing and organizing classifier performance without regard to class distributions or error costs. This can be helpful when investigating learning with skewed distributions or cost-sensitive learning.

Helpful reading includes:

Fawcett, Tom. "ROC graphs: Notes and practical considerations for researchers." Machine Learning 31 (2004): 1-38.

Swets, John A., Robyn M. Dawes, and John Monahan. "Better decisions through Science." Scientific American (2000): 83.

1076 questions
122
votes
18 answers

How to plot ROC curve in Python

I am trying to plot a ROC curve to evaluate the accuracy of a prediction model I developed in Python using logistic regression packages. I have computed the true positive rate as well as the false positive rate; however, I am unable to figure out…
user3847447
  • 1,291
  • 3
  • 11
  • 8
84
votes
5 answers

Roc curve and cut off point. Python

I ran a logistic regression model and made predictions of the logit values. I used this to get the points on the ROC curve: from sklearn import metrics fpr, tpr, thresholds = metrics.roc_curve(Y_test,p) I know metrics.roc_auc_score gives the area…
Shiva Prakash
  • 1,849
  • 4
  • 21
  • 25
67
votes
4 answers

Simple line plots using seaborn

I'm trying to plot a ROC curve using seaborn (python). With matplotlib I simply use the function plot: plt.plot(one_minus_specificity, sensitivity, 'bs--') where one_minus_specificity and sensitivity are two lists of paired values. Is there a…
Titus Pullo
  • 3,751
  • 15
  • 45
  • 65
43
votes
4 answers

ROC for multiclass classification

I'm doing different text classification experiments. Now I need to calculate the AUC-ROC for each task. For the binary classifications, I already made it work with this code: scaler = StandardScaler(with_mean=False) enc = LabelEncoder() y =…
42
votes
5 answers

Obtaining threshold values from a ROC curve

I have some models, using ROCR package on a vector of the predicted class percentages, I have a performance object. Plotting the performance object with the specifications "tpr", "fpr" gives me a ROC curve. I'm comparing models at certain thresholds…
Faydey
  • 725
  • 1
  • 5
  • 12
37
votes
2 answers

scikit-learn - ROC curve with confidence intervals

I am able to get a ROC curve using scikit-learn with fpr, tpr, thresholds = metrics.roc_curve(y_true,y_pred, pos_label=1), where y_true is a list of values based on my gold standard (i.e., 0 for negative and 1 for positive cases) and y_pred is a…
user2836189
  • 373
  • 1
  • 4
  • 4
32
votes
3 answers

ROC curve from training data in caret

Using the R package caret, how can I generate a ROC curve based on the cross-validation results of the train() function? Say, I do the following: data(Sonar) ctrl <- trainControl(method="cv", summaryFunction=twoClassSummary, …
January
  • 16,320
  • 6
  • 52
  • 74
32
votes
4 answers

Plotting a ROC curve in scikit yields only 3 points

TLDR: scikit's roc_curve function is only returning 3 points for a certain dataset. Why could this be, and how do we control how many points to get back? I'm trying to draw a ROC curve, but consistently get a "ROC triangle". lr =…
sapo_cosmico
  • 6,274
  • 12
  • 45
  • 58
29
votes
3 answers

Multiple ROC curves in one plot ROCR

Is it possible to plot the roc curve for diffrent classifiers in the same plot using the ROCR package? I've tried: >plot(perf.neuralNet, colorize=TRUE) >lines(perf.randomForest) But I get: Error en as.double(y) : cannot coerce type 'S4' to vector…
kahlo
  • 2,314
  • 3
  • 28
  • 37
27
votes
1 answer

How to plot precision and recall of multiclass classifier?

I'm using scikit learn, and I want to plot the precision and recall curves. the classifier I'm using is RandomForestClassifier. All the resources in the documentations of scikit learn uses binary classification. Also, can I plot a ROC curve for…
John Sall
  • 1,027
  • 1
  • 12
  • 25
27
votes
1 answer

How to interpret almost perfect accuracy and AUC-ROC but zero f1-score, precision and recall

I am training ML logistic classifier to classify two classes using python scikit-learn. They are in an extremely imbalanced data (about 14300:1). I'm getting almost 100% accuracy and ROC-AUC, but 0% in precision, recall, and f1 score. I understand…
KubiK888
  • 4,377
  • 14
  • 61
  • 115
23
votes
3 answers

R logistic regression area under curve

I am performing logistic regression using this page. My code is as below. mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv") mylogit <- glm(admit ~ gre, data = mydata, family =…
user2543622
  • 5,760
  • 25
  • 91
  • 159
23
votes
6 answers

ROC curve in R using ROCR package

Can someone explain me please how to plot a ROC curve with ROCR. I know that I should first run: prediction(predictions, labels, label.ordering = NULL) and then: performance(prediction.obj, measure, x.measure="cutoff", ...) I am just not clear…
spektra
  • 407
  • 2
  • 6
  • 9
22
votes
4 answers

How to compute AUC with ROCR package

I have fitted a SVM model and created the ROC curve with ROCR package. How can I compute the Area Under the Curve (AUC)? set.seed(1) tune.out=tune(svm ,Negative~.-Positive, data=trainSparse, kernel…
mac gionny
  • 333
  • 1
  • 3
  • 8
21
votes
2 answers

ValueError: Data is not binary and pos_label is not specified

I am trying to calculate roc_auc_score, but I am getting following error. "ValueError: Data is not binary and pos_label is not specified" My code snippet is as follows: import numpy as np from sklearn.metrics import…
user2374515
1
2 3
71 72