In this article
  1. Before you start
  2. Why interviewers ask this
  3. The confusion matrix from first principles
  4. Worked example
  5. Trade-offs and edge cases
  6. How to answer it in an interview
  7. Common mistakes
  8. Follow-up questions
  9. Sources

Before you start

Why interviewers ask this

A candidate who says "I would use accuracy" for a fraud model has not asked how rare fraud is. Classification metrics appear in machine learning rounds as "explain the confusion matrix", "ninety of a hundred rows are right, what are precision and recall", "which metric for fraud or a rare disease", and "what does the area under the curve (AUC) of the receiver operating characteristic (ROC) curve show". They often arrive inside a design discussion, where the metric choice reveals whether you tie the number to a cost, as in a machine learning (ML) system design round.

A weak answer lists metric names. A strong answer starts from the four counts, shows that accuracy can hide a failure, and picks the metric from the cost of each kind of error.

The confusion matrix from first principles

In plain words

Precision
Precision is the fraction of the examples a classifier labels positive that really are positive, computed as true positives divided by true positives plus false positives. It measures how well the model avoids false alarms.
Recall
Recall, also called sensitivity, is the fraction of the truly positive examples that the classifier finds, computed as true positives divided by true positives plus false negatives. It measures how few real cases are missed.
F1 score
The F1 score is the harmonic mean of precision and recall, which is high only when both are high. It is a single number that, unlike accuracy, ignores true negatives, so a large negative class does not inflate it.

Picture a smoke alarm. A true positive is an alarm during a fire, a false positive is an alarm during burnt toast, a false negative is silence during a fire, and a true negative is silence on a quiet day. Precision asks how many alarms were real fires. Recall asks how many fires set off an alarm.

The analogy breaks on cost. Burnt toast annoys, but a missed fire is a disaster, and a model's two error types often have costs that differ by far more than that.

In one precise sentence, the confusion matrix is the four counts from which every other classification metric is calculated.

Step 1: Four cells count every outcome

For a binary problem the confusion matrix has four cells: true negatives, false positives, false negatives and true positives. The scikit-learn 1.9.1 reference states that entry Cij is the number of observations known to be in group i and predicted to be in group j, so rows are true labels and columns are predictions, and flattening a binary matrix gives true negatives, false positives, false negatives, true positives in that order. It also notes that other references use the transposed layout, so check the axes before reading someone else's table.

Take 1,000 examples of which 10 are positive. A model that outputs "negative" for everything has 990 true negatives (tn), 0 false positives (fp), 10 false negatives (fn) and 0 true positives (tp)1. A better model might have 978, 12, 2 and 8.

The input is the true labels and the predictions. The output is four counts that sum to the number of examples.

Step 2: Accuracy hides the failure on rare classes

Accuracy, the share of predictions that are correct, can look excellent while a model fails completely on the rare class. Accuracy is the true positives plus true negatives divided by all examples. The model that says "negative" for everything scores 0.99 accuracy on the 1,000 examples above, yet its recall is 0 and its precision is undefined, because no example is flagged, and scikit-learn returns 0 with a warning1.

Balanced accuracy corrects for this. The scikit-learn guide defines balanced accuracy as the average of the recall on each class, which for two classes is the mean of sensitivity and specificity, so it is not inflated by imbalance. The do-nothing model scores 0.5, the level of chance. The better model scores 0.8941.

The input is the same four counts. The output shows that one number can hide an entire class.

Step 3: Precision, recall and F1 read the positive class

Precision and recall describe the positive class from two sides, and F1 combines them. The scikit-learn guide gives precision as tp/(tp+fp), recall as tp/(tp+fn) and the F-beta score as a weighted harmonic mean, with F1 the case where both count equally.

For the better model, precision is P=8/(8+12)=0.400 and recall is R=8/(8+2)=0.800. F1 is F1=2PR/(P+R)=0.533, and the library's F1 agrees with the hand calculation1. Accuracy for the same model is 0.986, which sounds nearly perfect and says nothing about the 12 false alarms.

This is also the answer to the classic "90 right, 10 wrong out of 100" question: the 10 errors could be all misses, all false alarms or any mix, and the metrics differ with each mix, as the worked example shows for 15 positives among 100 rows1.

The input is the four counts. The output is precision, recall and F1, each answering a different business question.

Step 4: The threshold moves the trade-off, and AUC summarizes it

A classifier that outputs scores becomes a yes-or-no classifier only after a threshold, and moving the threshold trades recall for precision. A lower threshold flags more cases, which catches more real positives and raises false alarms; a higher one does the reverse.

The ROC curve plots the true positive rate against the false positive rate as the threshold varies, and the area under the curve (AUC) of the receiver operating characteristic (ROC) curve, ROC AUC, is equivalent, in Fawcett's introduction to ROC analysis (section 7), to the probability that the classifier ranks a randomly chosen positive instance higher than a randomly chosen negative one. The scikit-learn guide adds that ROC does not require optimizing a threshold for each label, and the roc_auc_score reference computes it from prediction scores.

On synthetic scores for 20,000 examples with about 10 percent positives (2,034 in this seed), raising the threshold from −0.5 to 2.0 lifts precision from 0.132 to 0.422 and drops recall from 0.927 to 0.158, and the AUC is 0.75321. The threshold is chosen from the costs, not from the AUC.

Every metric comes straight from the four cells; the threshold fills themFour boxes: the scores and a threshold produce the four cells of the confusion matrix, and from the four cells accuracy and balanced accuracy, and precision, recall and F1, are each computed directly.Four cellstn 978, fp 12, fn 2, tp 8Accuracy, balancedbetter 0.986, 0.894; none0.99, 0.5Precision, recall, F1better model 0.400, 0.800,0.533Scores + thresholda new threshold, new cellsDiagram: Interview Clozo, CC BY 4.0 ·interview.clozo.ai/blog/confusion-matrix.html

Every metric is computed from the four cells, and the threshold decides what goes in them.CC BY 4.0 — source: What is a confusion matrix, and how do you read precision and recall?
Step-by-step description
  1. Rows are true labels, columns are predictions: 978, 12, 2 and 8 for the better model.
  2. The do-nothing model scores 0.99 accuracy but 0.5 balanced accuracy; the better model scores 0.986 and 0.894.
  3. Precision counts false alarms; recall counts misses; F1 combines them.
  4. The threshold decides the cells; a higher one trades recall for precision.
  • The do-nothing model on 1,000 examples with 10 positives has accuracy 0.99, balanced accuracy 0.5 and recall 0.
  • The better model has precision 0.400, recall 0.800, F1 0.533 and balanced accuracy 0.894.
  • Raising the threshold from -0.5 to 2.0 lifts precision from 0.132 to 0.422 and drops recall from 0.927 to 0.158.

Knowing it is half the job. Saying it is the other half.

Interview Clozo is an AI interview copilot for real interview rounds: it hears the question and puts a strong answer on your screen, and you say it in your own words. See the features or how it works.

Start Free Trial →

Worked example

A model with 8 true positives, 12 false positives, 2 false negatives and 978 true negatives has accuracy 0.986 but precision of only 0.400.
MetricFormulaValue
Accuracy(tp + tn) / all0.986
Precisiontp / (tp + fp)0.400
Recalltp / (tp + fn)0.800
F1harmonic mean of precision and recall0.533
Specificitytn / (tn + fp)0.988
Balanced accuracymean of recall and specificity0.894

The 1,000 examples hold 10 positives, so a model that never flags anything has accuracy 0.991.

Three models scored on the same 100 rows, 15 positive and 85 negative, all have accuracy 0.90 and have precision from 0.600 to 1.000 and recall from 0.333 to 1.000.
CasetnfpfntpPrecisionRecall
All 10 errors are misses8501051.0000.333
All 10 errors are false alarms75100150.6001.000
Errors split evenly8055100.6670.667

Each row has 15 positives (fn plus tp) and 85 negatives (tn plus fp), so the three models are scored on the same labels and differ only in where their 10 errors fall1.

Three models with the same accuracy behave in opposite waysGrouped bar chart of precision and recall for three models scored on the same 100 rows with 15 positives, all with accuracy 0.90: misses only gives precision 1.0 and recall 0.333, false alarms only 0.6 and 1.0, an even split 0.667 and 0.667.Score (ratio)00.250.50.751MissesFalse alarmsEven splitWhere the 10 errors fallPrecisionRecall10.60.6670.33310.667Diagram: Interview Clozo, CC BY 4.0 ·interview.clozo.ai/blog/confusion-matrix.html
Identical accuracy can hide opposite behavior, so report precision and recall together.CC BY 4.0 — source: What is a confusion matrix, and how do you read precision and recall?
Text description of the diagram
  • Three models scored on the same 100 rows, 15 positive and 85 negative, all have accuracy 0.90 and have precision from 0.600 to 1.000 and recall from 0.333 to 1.000.
  • If all 10 errors are misses, recall is 0.333; if all are false alarms, precision is 0.6.
Raising the threshold on synthetic scores trades recall for precision; the chart below plots all six thresholds.
ThresholdPrecisionRecallFalse positive rate
−0.50.1320.9270.692
0.50.2000.6830.309
1.00.2610.4930.158
2.00.4220.1580.024

The scores for positives are drawn from a Gaussian with mean 1 and for negatives mean 0, both with standard deviation 1, which makes the overlap and the trade-off visible; the Gaussian distribution page covers that shape1.

Raising the threshold trades recall for precision (AUC 0.7532)Line chart of precision and recall on synthetic scores at six thresholds from −0.5 to 2.0: precision rises from 0.132 to 0.422 while recall falls from 0.927 to 0.158; the AUC of the scores is 0.7532.Score (ratio)00.250.50.751−0.50.00.51.01.52.0ThresholdPrecisionRecallDiagram: Interview Clozo, CC BY 4.0 ·interview.clozo.ai/blog/confusion-matrix.html
Moving the threshold trades recall for precision; the AUC of 0.7532 summarizes the whole sweep in one number.CC BY 4.0 — source: What is a confusion matrix, and how do you read precision and recall?
Text description of the diagram
  • Raising the threshold from -0.5 to 2.0 lifts precision from 0.132 to 0.422 and drops recall from 0.927 to 0.158.
  • The AUC of the synthetic scores is 0.7532.

Trade-offs and edge cases

No single metric is right for every problem; the right one is set by what each error costs. A short guide follows, with the reasons.

  • Fraud or a rare disease: recall first, then precision. A missed case is usually the expensive error, so the threshold is lowered until recall meets a target, and precision is then watched to keep the review queue workable. State the costs as assumptions, since they depend on the business.
  • Spam filtering: precision first. A wrongly blocked real message is often worse than a missed spam message.
  • Balanced classes: accuracy is acceptable. When the classes are near equal, it carries real information, and the probability and statistics hub covers how to check the class balance.
  • Ranking quality: AUC. It compares scores independent of a threshold but says nothing about precision at the threshold you run; in the sweep above precision ranges from 0.132 to 0.422 at an AUC of 0.7532.
  • More than two classes. The matrix grows to one row and column per class, and the scikit-learn guide offers macro, micro and weighted averages, so name the average.
  • Probability quality. Precision and recall ignore how confident the model was; that is what cross-entropy loss scores, and a production system also needs machine learning operations (MLOps) monitoring of these counts over time.

How to answer it in an interview

Interviewer asks

Which metric would you use to evaluate a fraud classifier, and why?

A strong answer

I would start from the confusion matrix, because accuracy is misleading when fraud is rare: a model that flags nothing can be 99 percent accurate with zero recall. Recall is the share of real fraud caught and precision is the share of flags that are real. A missed fraud usually costs more than a false alarm, so I would set the threshold to reach a recall target and then watch precision to keep reviews affordable. I would report precision, recall and F1 at that threshold, and use ROC AUC only to compare ranking quality between models.

The spoken structure is: reject accuracy with the reason, define precision and recall, tie the threshold to cost, then name the metrics reported.

Common mistakes

  • "The model is 99 percent accurate, so it is good" (wrong). On rare classes accuracy is dominated by the majority class (right: report recall and precision for the rare class).
  • "Precision and recall are the same thing" (wrong). One counts false alarms and the other counts misses (right: define each by its denominator).
  • "Use F1 whenever classes are imbalanced" (wrong). F1 treats both errors as equally bad and ignores true negatives (right: use F-beta or a cost-based threshold when costs differ).
  • "A high AUC means the model is ready" (wrong). AUC ignores the threshold you will actually run (right: check precision and recall at the operating point).
  • "Read the matrix without checking the layout" (wrong). Rows are true labels in scikit-learn but other sources transpose it (right: confirm the axes).

Follow-up questions

What evaluation metric, and why that metric?

Pick it from the cost of each error and the class balance. For a rare positive class report precision and recall at the chosen threshold, with F1 as a single summary.

Out of 100 rows, 90 are classified correctly and 10 are not. How do you calculate precision and recall?

You cannot from those two numbers alone; you need the four cells. The 10 errors could all be misses, all false alarms or a mix, and the table above shows recall of 0.333, 1.0 or 0.667 for the same 90 percent accuracy on the same 15 positives.

What is precision good at measuring versus recall?

Precision measures how trustworthy a positive prediction is, so it matters when false alarms are costly. Recall measures how many real cases are found, so it matters when misses are costly.

What metrics are used to evaluate classification problems?

Accuracy, balanced accuracy, precision, recall, F1, specificity and ROC AUC all come from the confusion matrix or from the scores. The classical machine learning hub lists the models they are used with.

When would you use one metric over the other?

Use recall when misses are the expensive error, precision when false alarms are, F1 when you need one number and both matter, and AUC to compare models before choosing a threshold. A training signal such as gradient descent on a loss is a separate matter from these reporting metrics.

Key takeaways
  • A confusion matrix counts true and false positives and negatives; rows are true labels and columns are predictions in scikit-learn.
  • Accuracy can be 0.99 for a model with zero recall on a rare class.
  • Precision is tp over tp plus fp; recall is tp over tp plus fn; F1 is their harmonic mean.
  • The threshold trades recall for precision; ROC AUC summarizes ranking quality across all thresholds.
  • Choose the metric from the cost of each error, and say the costs as assumptions.

Sources

  1. sklearn.metrics.confusion_matrix, scikit-learn 1.9.1 documentation — scikit-learn developers (page shows version only; read 2026-10-24), 24 Oct 2026
  2. Metrics and scoring: quantifying the quality of predictions, scikit-learn 1.9.1 documentation — scikit-learn developers (page shows version only; read 2026-10-24), 24 Oct 2026
  3. An introduction to ROC analysis, Tom Fawcett, Pattern Recognition Letters 27(8):861-874 — Elsevier (read as the author's PDF copy, section 7; read 2026-10-24), 24 Oct 2026
  4. sklearn.metrics.roc_auc_score, scikit-learn 1.9.1 documentation — scikit-learn developers (page shows version only; read 2026-10-24), 24 Oct 2026