ROC Curve
What is a ROC curve?
A ROC curve (receiver operating characteristic curve) is a chart of how well a binary classifier separates two classes. It plots the true positive rate against the false positive rate at every decision threshold. The area under it, the AUC, sums the curve up as one number from 0 to 1, where 0.5 is chance and 1 is perfect.

Score histograms, confusion matrix, ROC curve and precision-recall curve for a simulated classifier with 5% positives (sample data). Try the interactive version.
- Each point on a ROC curve is one threshold, turned into a confusion matrix and then into two rates: true positives caught and false alarms raised.
- AUC is the probability that a randomly chosen positive gets a higher score than a randomly chosen negative.
- The diagonal is a model with no skill. A curve below it has its scores the wrong way round.
- With rare positives, the precision-recall curve and average precision show problems the ROC curve hides.
- AUC judges the ranking. A deployed model also needs a threshold, chosen from the costs of each kind of error.
Classifiers, scores and the decision threshold
A binary classifier sorts cases into two classes: spam or not spam, fraud or genuine, disease present or absent. By convention the class you are looking for is the positive class, whatever it means in real life.
Most classifiers don't output a yes or a no. They output a score, often a probability between 0 and 1, and a threshold turns it into a decision: a score at or above the threshold means "positive". Raise the threshold and the model flags fewer cases, missing more real positives but raising fewer false alarms. Lower it and the reverse happens.
A single accuracy figure describes the model at one threshold only. A ROC curve shows all of them at once, so you can judge the model's ranking separately from where you set the cut-off.
The confusion matrix
At any threshold, every case falls into one of four boxes. The table that counts them is the confusion matrix:
| Predicted positive | Predicted negative | |
|---|---|---|
| Actually positive | True positive (TP) | False negative (FN), a miss |
| Actually negative | False positive (FP), a false alarm | True negative (TN) |
Take ten test cases, four positive and six negative, with these model scores (the same cases are used throughout this page):
| Case | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| Score | 0.95 | 0.80 | 0.70 | 0.60 | 0.50 | 0.40 | 0.35 | 0.25 | 0.15 | 0.10 |
| Actual class | + | + | − | + | − | − | + | − | − | − |
At a threshold of 0.5, cases 1 to 5 are predicted positive. Three of them are real positives and two are not, and one positive (case 7) is missed:
| Predicted + | Predicted − | |
|---|---|---|
| Actual + | TP = 3 | FN = 1 |
| Actual − | FP = 2 | TN = 4 |
Sensitivity, specificity, precision and recall
The ROC and precision-recall curves are built from four ratios of those counts:
| Rate | Also called | Formula | At threshold 0.5 |
|---|---|---|---|
| True positive rate (TPR) | Recall, sensitivity, hit rate | 3 / 4 = 0.75 | |
| False positive rate (FPR) | Fall-out, 1 − specificity | 2 / 6 = 0.33 | |
| Specificity | True negative rate | 4 / 6 = 0.67 | |
| Precision | Positive predictive value | 3 / 5 = 0.60 |
The ROC curve plots TPR against FPR. The precision-recall curve plots precision against recall (which is TPR again). Accuracy, (TP + TN) / total, is 0.70 here.
Precision vs recall
Recall answers "of all the real positives, how many did we catch?". Precision answers "of everything we flagged, how much was real?". Recall divides by the actual positives; precision divides by the predicted positives. A spam filter that lets some spam through has low recall; one that sends real mail to the spam folder has low precision.
Lowering the threshold usually raises recall and lowers precision. The F1 score combines the two into one number.
F1 score
The F1 score is the harmonic mean of precision and recall :