Data Science Interview Q&A: Accuracy, Precision, Recall and Error Costs
Explain accuracy, precision, recall and error costs through interview questions and checked arithmetic.
1. Is high accuracy enough to choose a classifier?
No. Start with the decision the model supports and the cost of each kind of mistake. Consider a practice dataset of 100 support requests, only five of which need urgent escalation. Predicting every request as ordinary gives 95 correct decisions but misses every urgent request. The accuracy is 95%, yet the system does none of the intended urgent detection.
This example is deliberately small and invented. It is a reasoning exercise rather than evidence that any real support model performs at a particular level.
2. What do precision and recall tell you?
Precision asks how many predicted positives were actually positive. Recall asks how many actual positives were found. With urgent escalation defined as the positive class, false positives create unnecessary escalations and false negatives miss urgent cases. Neither metric identifies the acceptable trade-off by itself; the people responsible for the workflow must define it.
3. Can you calculate these metrics without a machine-learning library?
The following JavaScript is a transparent arithmetic exercise, not model training. Predictions and actual labels use 1 for urgent and 0 for ordinary.
const actual = [1, 1, 1, 0, 0, 0];
const predicted = [1, 0, 1, 1, 0, 0];
let tp = 0, fp = 0, fn = 0, tn = 0;
actual.forEach((label, i) => {
const guess = predicted[i];
if (label === 1 && guess === 1) tp++;
else if (label === 0 && guess === 1) fp++;
else if (label === 1 && guess === 0) fn++;
else tn++;
});
console.log({tp, fp, fn, tn});
console.log(tp / (tp + fp), tp / (tp + fn));
Expected counts are tp 2, fp 1, fn 1, tn 2. Both precision and recall equal 2/3, approximately 0.667. Accuracy is 4/6. The arithmetic example was checked locally; no live model was trained. In reusable code also validate equal array lengths, permitted labels and zero denominators instead of silently returning an invalid value.
4. Does F1 decide the best business threshold?
F1 balances precision and recall through their harmonic mean. It does not contain your organisation's financial or operational error costs. A threshold chosen to maximise F1 might still overload the escalation team. Evaluate realistic capacity and consequences alongside metrics; do not present a single number as a complete deployment decision.
5. Where should a threshold be selected?
Use validation data or appropriate cross-validation for development choices. Preserve a separate test set for a final estimate. Repeatedly adjusting the threshold after looking at test results makes that set part of development. Time-dependent or grouped observations need a split that reflects how the system will be used.
Practice interview follow-up
Change the second prediction from 0 to 1. The counts become tp 3, fp 1, fn 0, tn 2: recall becomes 1 and precision becomes 0.75. Explain both changes and identify which error disappeared. Then describe an operational case in which this extra escalation is worth accepting. There is no universal answer without the use case.
Prepared by AI Leaf Global Learn for classroom learners in Mudichur/Tambaram, Chennai, and online learners across India. Confirm current batch availability.
Data Science course.
Official scikit-learn evaluation guide.