How does the ROC curve and AUC work?
- Authors
- Name
- Amit Shekhar
- Published on
An ROC curve is a graph that shows how good a model is at telling two things apart, and AUC is the area under that curve, one number to compare models.
In this blog, we will learn about how the ROC curve and AUC work. We will also see why plain accuracy is not enough, the True Positive Rate and the False Positive Rate, how the threshold changes them, how to draw an ROC curve step by step, how to read an AUC score, and where it works well and where it fails.
We will cover the following:
- What is the ROC curve and AUC?
- The problem: why plain accuracy is not enough
- Score and threshold
- The four outcomes of a prediction
- Two key numbers: True Positive Rate and False Positive Rate
- How the threshold changes TPR and FPR
- Drawing the ROC curve step by step
- What is AUC?
- How to read an AUC score
- AUC as a simple probability
- Where the ROC curve and AUC are used
- Limitations of the ROC curve and AUC
I am Amit Shekhar, Founder @ Outcome School, I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.
I teach AI and Machine Learning at Outcome School.
Let's get started.
What is the ROC curve and AUC?
ROC stands for Receiver Operating Characteristic. It is an old name from radar systems in World War II, where operators had to decide if a blip on a screen was a real enemy plane or just noise.
An ROC curve is a graph that shows how good a model is at telling two things apart, for example "spam" and "not spam".
AUC (Area Under the Curve) is a single number that measures how much space sits under that ROC curve. It squeezes the whole picture into one score between 0 and 1.
The ROC curve is the picture, and the AUC is the score for that picture. The higher the AUC, the better the model.
The problem: why plain accuracy is not enough
Suppose we build a model that checks if an email is spam or not spam. We test it on 100 emails. The model gets 90 right. So its accuracy is 90 percent.
Let's say that out of those 100 emails, only 10 were actually spam and 90 were normal. Now imagine a lazy model that simply says "not spam" for every single email. It never even looks at the content.
This lazy model would still be right 90 times, because 90 emails really were not spam. So it also scores 90 percent accuracy, while doing nothing useful at all.
So, accuracy can fool us, especially when one group is much larger than the other.
We need a better way to measure how well a model truly separates the two groups. So, here comes the ROC curve and AUC to the rescue.
Score and threshold
Before we go deeper, we must understand two ideas: the score and the threshold.
Most models that sort things into two groups do not just say a flat "yes" or "no". Instead, they give a score, usually a number between 0 and 1, that tells how confident it is.
A score close to 1 means "I am very sure this is spam". A score close to 0 means "I am very sure this is not spam". A score like 0.5 means "I am not sure".
We have a detailed blog on Linear Regression vs Logistic Regression that explains how such a model turns its output into a probability between 0 and 1.
Now, to make a final decision, we need a cut-off line. That cut-off line is called the threshold.
The threshold is the score above which we call something "spam".
For example, if we set the threshold at 0.5, then any email with a score above 0.5 is marked as spam, and anything below is marked as not spam.
Let's see it as below:
score: 0.0 ---------------- 0.5 ---------------- 1.0
low confidence | high confidence
(sure: not spam) | (sure: spam)
marked "not spam" | marked "spam"
(score below cut-off) | (score above cut-off)
threshold = 0.5
Here, we can see the score line running from 0.0 on the left to 1.0 on the right. The threshold is the vertical cut-off line. Every email lands somewhere on this line based on its score. Emails to the left of the cut-off are marked "not spam", and emails to the right are marked "spam".
So, we can move this threshold up or down, and this choice changes the results, as we will see soon.
The four outcomes of a prediction
When our model makes a guess, there are exactly four possible outcomes. The ROC curve is built on these four.
Let's say "spam" is the thing we are trying to catch. We call it the positive class. "Not spam" is the negative class.
The four outcomes are like below:
Actual answer
Spam Not spam
+----------------+----------------+
Model says | True Positive | False Positive |
"Spam" | (correct) | (mistake) |
+----------------+----------------+
Model says | False Negative | True Negative |
"Not spam" | (mistake) | (correct) |
+----------------+----------------+
Here, we can see all four cases. A True Positive is real spam that we correctly caught. A True Negative is a normal email we correctly let through. A False Positive is a normal email we wrongly marked as spam. A False Negative is real spam that we wrongly let through.
This four-box table is called the confusion matrix, because it shows where the model gets confused.
The two correct boxes are the True Positive and the True Negative. The two mistakes are the False Positive and the False Negative.
To master Evaluation and Testing, Supervised and Unsupervised Learning, and Logistic Regression from the ground up, check out our AI and Machine Learning Program at Outcome School.
Two key numbers: True Positive Rate and False Positive Rate
Now we build the two numbers that the ROC curve is made of.
The first is the True Positive Rate, often shortened to TPR.
The True Positive Rate answers one question: out of all the emails that really were spam, how many did we catch?
TPR = spam emails we caught / all emails that were really spam
Here, we can see that TPR rewards us for catching the real spam. A TPR of 1 means we caught every single spam email. This is also called sensitivity or recall.
The second is the False Positive Rate, often shortened to FPR.
The False Positive Rate answers a different question: out of all the normal emails, how many did we wrongly mark as spam?
FPR = normal emails wrongly marked as spam / all emails that were really normal
Here, we can see that FPR punishes us for false alarms. An FPR of 0 means we never wrongly flagged a normal email.
Let's plug in real numbers for the sake of understanding. Suppose there are 10 real spam emails and 90 normal emails. At some threshold, our model catches 8 of the 10 spam emails and wrongly flags 9 of the 90 normal ones.
TPR = 8 / 10 = 0.8 (caught 8 out of 10 spam)
FPR = 9 / 90 = 0.1 (false-flagged 9 out of 90 normal)
Here, we can see that this threshold gives us one pair, a TPR of 0.8 and an FPR of 0.1. That pair is a single point we will later plot on the graph.
So, what do we want? We want a high TPR, which means we catch lots of spam. And we want a low FPR, which means we raise very few false alarms.
In short, high TPR and low FPR is the goal.
Planning your move into AI?
No matter which tech domain you work in today, with your effort, you can transition to these roles:
- AI Engineer
- Forward Deployed Engineer
- AI Agent Engineer
- Harness Engineer
- Voice AI Engineer
- AI Architect
- LLM Engineer
- LLM Inference Engineer
- Gen AI Engineer
- MLOps Engineer
- ML Engineer
- Deep Learning Engineer
Our AI and Machine Learning Program at Outcome School takes you there.
How the threshold changes TPR and FPR
The TPR and the FPR are not fixed. They change as we slide the threshold up and down.
Let's think it through.
If we set the threshold very low, near 0, then almost every email scores above it. So the model marks almost everything as spam. We catch all the real spam, so TPR is high. But we also flag many normal emails, so FPR is high too.
If we set the threshold very high, near 1, then almost nothing scores above it. The model marks almost nothing as spam. We raise very few false alarms, so FPR is low. But we also miss most of the real spam, so TPR is low.
Let's see it as below:
Low threshold (near 0): almost everything is called "spam"
0.0 -|------------------------------------------- 1.0
| <----------- marked "spam" ------------->
catch all spam (high TPR), but many false alarms (high FPR)
High threshold (near 1): almost nothing is called "spam"
0.0 ---------------------------------------|----- 1.0
marked "spam" ----> |
few false alarms (low FPR), but miss most spam (low TPR)
Here, we can see the same score line with the cut-off in two positions. When the cut-off sits on the far left, the "spam" region is huge, so we catch everything but also flag many normal emails. When the cut-off sits on the far right, the "spam" region is tiny, so we flag almost nothing, which keeps false alarms low but lets real spam slip through.
Let's tabulate this for clarity.
| Threshold | TPR (catch spam) | FPR (false alarms) |
|---|---|---|
| Very low | High | High |
| Medium | Medium | Medium |
| Very high | Low | Low |
Here, we can see the trade-off. Usually, there is no single threshold that gives a perfect TPR and a perfect FPR at the same time. Every threshold gives us one pair of numbers, one TPR and one FPR.
So, the question becomes: instead of picking one threshold, why not try every threshold and see all the pairs together? That is exactly what the ROC curve does.
Drawing the ROC curve step by step
Now we are ready to draw the ROC curve.
The ROC curve is a graph with two axes. The bottom axis, going left to right, is the False Positive Rate. The side axis, going bottom to top, is the True Positive Rate.
To draw the curve, we follow these steps.
Step 1: We pick a threshold, for example 0.9.
Step 2: Using that threshold, we calculate the TPR and the FPR. This gives us one point on the graph.
Step 3: We lower the threshold a little, say to 0.8, and calculate the TPR and FPR again. This gives us another point.
Step 4: We repeat this for many thresholds, from high all the way down to low.
Step 5: We connect all the points with a line. That line is the ROC curve.
Let's see it as below:
TPR
1.0 | * * * * * * * * * * * *
| * * .
| * .
| * . (good model bows
| * . toward the
| * . top-left corner)
| * .
|* . (the dotted diagonal line
|* . is a random guesser)
|* .
0.0 +-------------------------------------- FPR
0.0 1.0
Here, we can see two lines. The dotted diagonal line, going from the bottom-left to the top-right, is what a model that guesses randomly would produce. It is our baseline for "no skill".
The curved line that bows up toward the top-left corner is a good model. The closer the curve hugs the top-left corner, the better the model is, because the top-left corner means high TPR and low FPR at the same time, which is exactly our goal.
So, the ROC curve shows us how the model behaves at every threshold, all in one picture.
A quick note for you
No matter which tech domain you work in, get familiar with these topics:
- LLM
- RAG
- MCP
- Agent
- Fine-tuning
- Quantization
We put it all together in one video:
AI Engineering Explained: LLM, RAG, MCP, Agent, Fine-Tuning, and Quantization
No need to stop reading - bookmark it and watch later when you get time. Future you will thank you.
Now, let's get back to the topic.
What is AUC?
Looking at a whole curve is useful, but sometimes we just want one number to compare two models quickly. So, here comes the AUC into the picture.
AUC stands for Area Under the Curve. It measures the amount of area that sits underneath the ROC curve.
The whole graph is a square that is 1 unit wide and 1 unit tall. So the total area is 1. This means the AUC is always a number between 0 and 1.
Let's see it as below:
TPR
1.0 | _____________________
| _/#####################|
| /#######################|
| /########################| ### = area under the curve
| /#########################| (this is the AUC)
| /##########################|
| /###########################|
|/############################|
0.0 +-----------------------------+ FPR
0.0 1.0
Here, we can see the shaded area marked with hashes. That shaded region under the curve is the AUC. A curve that bows higher toward the top-left covers more area, so it has a bigger AUC. A curve that stays near the diagonal covers about half the square, so its AUC is near 0.5.
So, a bigger AUC means a better model.
How to read an AUC score
Now, let's learn how to read the AUC number.
- AUC = 1.0 means a perfect model. It separates spam from normal email with no mistakes. This almost never happens in the real world.
- AUC = 0.5 means the model is no better than flipping a coin. It has no real skill. This matches the dotted diagonal line.
- AUC below 0.5 means the model is worse than random. Usually this means our labels are flipped somewhere, and the model is actually learning the opposite.
As a rough rule of thumb that many people use:
| AUC value | What it usually means |
|---|---|
| 0.9 to 1.0 | Great |
| 0.8 to 0.9 | Good |
| 0.7 to 0.8 | Fair |
| 0.6 to 0.7 | Weak |
| 0.5 to 0.6 | Almost useless |
| Around 0.5 | Random guessing |
Here, we can see a quick guide. We must remember these are general guidelines, not strict laws. What counts as a "good" AUC depends on the problem. For a hard medical task, an AUC of 0.75 is often very valuable.
Stay updated: Subscribe to our newsletter to get our latest AI and Machine Learning blogs straight to your inbox.
AUC as a simple probability
There is one more way to understand AUC.
The AUC is exactly equal to this: the chance that the model gives a higher score to a random spam email than to a random normal email.
Let's make it concrete. Suppose we pick one real spam email and one real normal email, both at random. We ask the model to score both.
If the AUC is 0.9, it means that 9 times out of 10, the model correctly gives the spam email a higher score than the normal one.
Let's see it as below:
Pick one random spam email and one random normal email
| |
↓ ↓
model scores it model scores it
score = 0.82 score = 0.31
| |
+---------------+------------------+
↓
Is the spam score higher than the normal score?
|
Yes ----> this pair is ranked correctly
AUC = fraction of all such pairs that are ranked correctly
Here, we can see the test behind AUC. We take one spam email and one normal email, let the model score both, and check if the spam one got the higher score. The AUC is the share of all such random pairs where the spam email is ranked above the normal one.
If the AUC is 0.5, it means the model is right only half the time, which is the same as guessing.
So, the AUC measures how well the model ranks a positive example above a negative one. This is why AUC does not care about which exact threshold we pick. It looks at the ordering across all thresholds at once.
Where the ROC curve and AUC are used
Let's see where the ROC curve and AUC are used.
These tools are used almost everywhere that a model must answer a yes-or-no question. Here are a few examples:
- Medicine, to check how well a test tells sick patients apart from healthy ones.
- Banks, to judge how well a model spots fraud among normal transactions.
- Email services, to measure how well a filter separates spam from real mail.
- Machine learning teams, to compare two models and pick the one that separates the classes better.
The ROC curve and AUC remain a standard way to judge a model that sorts things into two groups, because one number, the AUC, lets us compare models without picking a threshold.
Limitations of the ROC curve and AUC
The ROC curve and AUC are useful, but they are not perfect for every job.
First, the ROC curve can look too good when one group is very rare. For example, if fraud is only 1 in 10,000 cases, the ROC curve can still look strong while the model is, in practice, raising too many false alarms. In such heavily uneven cases, a different graph called the Precision-Recall curve often tells a more honest story.
Second, the AUC gives us one overall number. But in real life, we still have to choose one threshold to actually use. The AUC does not tell us which threshold to pick. It only tells us how good the ranking is across all of them.
Third, the AUC treats all mistakes as equal. But in real life, missing a cancer case is far worse than a false alarm. The AUC does not know the cost of each mistake.
Here, we can see the trade-off. The ROC curve and AUC give us a threshold-free way to compare models, but we still need our own judgment to pick the final cut-off and to weigh the cost of each kind of mistake.
Frequently Asked Questions
What does ROC stand for?
ROC stands for Receiver Operating Characteristic. It is an old name that comes from radar systems in World War II, where operators had to decide if a blip on a screen was a real enemy plane or just noise. Today, the ROC curve shows how good a model is at telling two things apart.
Is the True Positive Rate the same as recall?
Yes. The True Positive Rate is also called recall or sensitivity. It answers one question: out of all the cases that were really positive, how many did the model catch? A True Positive Rate of 1 means the model caught every single positive case.
Does AUC tell us which threshold to use?
No. AUC does not tell us which threshold to pick. It measures how well the model ranks a positive example above a negative one across all thresholds at once. In real life, we still have to choose one threshold ourselves and weigh the cost of each kind of mistake.
When should we use a Precision-Recall curve instead of an ROC curve?
We should consider a Precision-Recall curve when one group is very rare, for example fraud that happens in only 1 in 10,000 cases. In such heavily uneven cases, the ROC curve can still look strong while the model raises too many false alarms, and the Precision-Recall curve often tells a more honest story.
That's it for now.
Thanks
Amit Shekhar
Founder @ Outcome School
You can connect with me on:
Follow Outcome School on:
