
Dan Patiño
AI Strategy & Innovation at Coderhouse
Artificial Intelligence
A ROC curve (receiver operating characteristic curve) is a chart that shows how well a classification model separates two classes across every possible decision threshold. AUC (area under the curve) summarizes that chart in a single number between 0 and 1: the higher it is, the better the model ranks positive cases above negative ones.
Why it matters now: classification models are everywhere, from fraud detection and churn prediction to spam filters and AI content moderation. Accuracy alone often hides how a model really behaves, especially with imbalanced data. ROC curves and AUC let you compare models fairly and pick a threshold that fits the business cost of mistakes, which is why they appear in almost every machine learning evaluation and interview.
From scores to decisions: why thresholds matter
Most classifiers, such as logistic regression, do not output a yes or no directly. They output a score or probability, and you choose a threshold: above 0.5 is “fraud,” below is “legit,” for example. Move the threshold down and you catch more fraud but flag more innocent customers; move it up and you flag fewer customers but miss more fraud.
Each threshold produces a different confusion matrix. A ROC curve plots all of them at once, so you can see the full trade-off instead of a single snapshot.
How a ROC curve is built
The ROC curve uses two rates computed at each threshold:
True positive rate (TPR), also called recall or sensitivity: the share of actual positives the model correctly flags.
False positive rate (FPR): the share of actual negatives the model wrongly flags as positive.
Plot FPR on the horizontal axis and TPR on the vertical axis, then connect the points from the strictest threshold (nothing flagged, point 0,0) to the most lenient (everything flagged, point 1,1). Google’s Machine Learning Crash Course on ROC and AUC walks through this visually.
Reading the shape
A curve hugging the top-left corner means the model reaches high recall with few false positives: strong separation.
The diagonal line from (0,0) to (1,1) is what random guessing produces.
A curve below the diagonal means the model is worse than random, often a sign that labels or scores are inverted.
What AUC means
AUC is the area under the ROC curve. It has a useful interpretation: it equals the probability that the model gives a randomly chosen positive example a higher score than a randomly chosen negative one.
AUC = 0.5: no better than chance.
AUC around 0.7 to 0.8: useful separation for many business problems.
AUC above 0.9: very strong ranking, worth double-checking for data leakage.
AUC = 1.0: perfect separation, which in real projects usually signals a bug or a leaked feature.
Because AUC does not depend on any single threshold, it is good for comparing models during development. It is also insensitive to how scores are scaled, as long as the ranking stays the same.
Computing ROC and AUC in Python
In scikit-learn, roc_curve(y_true, y_score) returns the FPR, TPR, and thresholds, and roc_auc_score(y_true, y_score) returns the AUC. Pass predicted probabilities or decision scores, not hard 0/1 predictions, otherwise you only get one point on the curve. The scikit-learn model evaluation guide documents these metrics, and its ROC example shows multiclass extensions using one-vs-rest averaging.
When ROC AUC can mislead
Highly imbalanced data
When positives are rare, such as 1 fraud case in 1,000 transactions, a small false positive rate can still mean thousands of false alarms. ROC AUC can look excellent while precision is poor. In those cases, also check the precision-recall curve and its average precision, which focus on how trustworthy the positive predictions are.
Ignoring business costs
AUC treats all thresholds equally, but your business only uses one. A model with slightly lower AUC may perform better at the threshold you actually deploy. Always evaluate the chosen operating point with real costs: the price of a missed churner versus the cost of an unnecessary retention discount, for instance.
Calibration is a separate question
A high AUC says the model ranks cases well, not that its probabilities are accurate. If you need a 0.8 score to mean “80% likely,” check calibration separately.
How to pick a threshold from the ROC curve
Define the cost of a false positive and a false negative in business terms.
Set a constraint if you have one, such as “no more than 5% of good customers flagged.”
Find the point on the curve that meets the constraint with the highest TPR, or that minimizes expected cost.
Validate that threshold on a held-out test set and monitor it in production, since data drift can move the best point over time.
FAQ
What is a good AUC score?
It depends on the problem. In noisy domains like marketing response, 0.7 can be valuable; in medical screening, teams often expect much higher. Compare against a simple baseline model rather than a fixed rule.
Is AUC the same as accuracy?
No. Accuracy measures correct predictions at one threshold. AUC measures ranking quality across all thresholds, and it is far less affected by class imbalance than accuracy.
Can I use ROC AUC for multiclass problems?
Yes, by computing one-vs-rest or one-vs-one curves for each class and averaging the AUCs, either equally (macro) or weighted by class frequency.
Build and evaluate models with live practice
If you want to practice training, evaluating, and deploying classification and AI models with guidance from practitioners, Coderhouse offers live online courses with one class per week:
AI Engineering Course: 8 weeks for experienced developers moving into AI engineering, covering LLM applications, retrieval, agents, evaluation, and deployment.
Data Analytics Course: 11 weeks for career switchers, analysts, and data-driven professionals, covering metrics, SQL, Python, visualization, experimentation, and AI-assisted analysis.
I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.