Model evaluation metrics interview questions, computed by hand
In this article (5 sections)
Related programme: the Data Science course (6 months; ₹1,30,000 (inclusive of GST) · EMI from ₹5,000/month).
Model evaluation questions in interviews check whether you can pick a metric that matches the business cost of each error, and compute it without a library when asked. The core is a confusion matrix: from its four counts come precision, recall, specificity, F1 and accuracy. Beyond it, you need to explain ROC-AUC, PR-AUC, calibration and regression metrics, and to choose a threshold from costs. Every number below comes from the small, hypothetical example in the code blocks, so you can check the arithmetic yourself.
Start with one confusion matrix
A hypothetical fraud model scored 1,000 transactions, 50 of which were fraud. At a threshold of 0.5 it flagged 60, of which 40 were fraud.
tp, fp = 40, 20 # flagged: 60
fn = 50 - tp # fraud missed
tn = 1000 - tp - fp - fn
precision = tp / (tp + fp)
recall = tp / (tp + fn)
specificity = tn / (tn + fp)
accuracy = (tp + tn) / 1000
f1 = 2 * precision * recall / (precision + recall)
print(f"TP {tp} FP {fp} FN {fn} TN {tn}")
print(f"precision {precision:.3f} recall {recall:.3f} specificity {specificity:.3f}")
print(f"accuracy {accuracy:.3f} F1 {f1:.3f}")
print(f"accuracy of flagging nothing: {(1000 - 50) / 1000:.3f}")Precision 0.667, recall 0.800, specificity 0.979, accuracy 0.970 and F1 0.727. A model that flags nothing scores 0.950 accuracy — which is why accuracy alone is the wrong headline here.
Questions, weak answers and strong answers
| Question | Weak answer | Strong answer |
|---|---|---|
| What is precision? | "How accurate the model is." | Of the cases flagged positive, the share that are truly positive: TP / (TP + FP). |
| Recall versus specificity? | "They're the same thing for different classes." | Recall is the share of actual positives caught; specificity is the share of actual negatives correctly left alone. |
| Why does F1 use the harmonic mean? | "It's the standard." | The harmonic mean is pulled toward the smaller value, so a model cannot score well by maximising one of precision or recall and neglecting the other. |
| What does AUC 0.5 mean? | "50% accuracy." | Ranking is no better than random: a random positive is as likely to score below a random negative as above it. |
| When prefer PR-AUC over ROC-AUC? | "When the data is big." | When positives are rare: ROC-AUC includes the large true-negative count and can look good while precision at useful thresholds is poor. |
| A model's AUC went up. Better? | "Yes." | Its ranking improved overall, but check precision and recall at the threshold you will operate at; AUC averages over thresholds you will never use. |
| RMSE or MAE? | "RMSE is more common." | RMSE penalises large errors more heavily; MAE treats all errors linearly and is easier to explain in units. Choose by whether a few large misses are especially costly. |
| What is calibration? | "Tuning the model." | Whether predicted probabilities match observed frequencies: among cases scored 0.2, about 20% should be positive. Needed whenever the score is used as a probability, such as pricing or expected loss. |
ROC-AUC by counting pairs
Interviewers sometimes ask what AUC means concretely. It equals the probability that a randomly chosen positive scores higher than a randomly chosen negative, with ties counting half. You can compute it by counting pairs:
scores_pos = [0.9, 0.8, 0.55, 0.4]
scores_neg = [0.7, 0.5, 0.3, 0.2, 0.1]
wins = 0.0
for p in scores_pos:
for n in scores_neg:
wins += 1.0 if p > n else 0.5 if p == n else 0.0
auc = wins / (len(scores_pos) * len(scores_neg))
print(f"{wins:.0f} of {len(scores_pos) * len(scores_neg)} pairs ordered correctly, AUC {auc:.2f}")Seventeen of twenty positive-negative pairs are ordered correctly, so AUC is 0.85. The explanation interviewers want: AUC measures ranking, not probability accuracy, and it is unchanged if you apply any order-preserving transformation to the scores.
Choosing a threshold from costs
Question: "Missing a fraud costs ₹8,000 on average; reviewing a flagged transaction costs ₹150. Where should the threshold be?"
The strong answer computes expected cost at each candidate threshold rather than picking the F1 maximum. With the hypothetical counts below:
missed_cost, review_cost = 8000, 150
# threshold: (TP, FP) among 1,000 transactions with 50 fraud
candidates = {0.7: (30, 5), 0.5: (40, 20), 0.3: (46, 80), 0.1: (49, 300)}
for t, (tp, fp) in candidates.items():
fn = 50 - tp
cost = fn * missed_cost + (tp + fp) * review_cost
print(f"threshold {t}: flagged {tp + fp:>3}, missed {fn:>2}, cost Rs {cost:,}")The costs are ₹1,65,250 at 0.7, ₹89,000 at 0.5, ₹50,900 at 0.3 and ₹60,350 at 0.1. With these assumptions, 0.3 is cheapest — a lower threshold than the one that maximises F1, because a missed fraud costs more than fifty reviews. Point out that the ranking changes if review capacity is limited, which turns the problem into "top N by score" instead.
Follow-ups to prepare
- Class imbalance: say you would report precision, recall and PR-AUC, and consider class weights; resampling changes the base rate, so recalibrate probabilities afterwards.
- Multi-class: macro averaging weights every class equally; micro averaging weights every row equally and is dominated by large classes.
- Validation design: a metric is only as trustworthy as the split behind it; for time-ordered data, test on a later period.
- Business metric link: end by tying the offline metric to what changes in production — reviews per day, losses avoided, customers contacted.
The same cut-off-from-economics idea appears in the banking and credit case bank, and the ML fundamentals bank covers the model-side questions. Metrics chosen from business costs are practised on case datasets in the Data Science programme.
Frequently asked questions
When should I use F1 score instead of accuracy?
Use F1 when the positive class is rare and you care about both missed positives and false alarms roughly equally. Accuracy is dominated by the majority class in imbalanced data. If the two error types have very different costs, choose a threshold from those costs instead of relying on F1.
Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.
This article is part of our Data Science programme — 6 months. From data foundations to machine learning, deep learning and deployment.
Explore Data Science