Calculate Precision, Recall, and F1
Company: Intuit
Role: Data Scientist
Category: Statistics & Math
Difficulty: medium
Interview Round: Technical Screen
##### Question
You are given a list of binary classification outputs, where class `1` is the positive class. Each record contains:
- `actual` (INT, `0` or `1`)
- `predicted` (INT, `0` or `1`)
- `confidence` (FLOAT, the model's confidence score for the positive class)
Example record: `{"actual": 1, "predicted": 0, "confidence": 0.93}`.
Using the provided `actual` and `predicted` labels, write Python or pseudocode that:
1. Computes the confusion-matrix counts for the positive class: `TP`, `FP`, `TN`, `FN`.
2. Calculates `precision`, `recall`, and the `F1 score` over the full dataset.
3. Explains how you would derive `predicted` from `confidence` if the interviewer asks you to apply a decision threshold instead of using the provided predicted labels, and how the metrics change as the threshold changes.
4. Handles edge cases where a denominator becomes zero (for example, no predicted positives or no actual positives).
Quick Answer: This Intuit Data Scientist technical-screen question tests your ability to compute confusion-matrix counts (TP, FP, TN, FN) and derive precision, recall, and F1 for the positive class from binary classification outputs. It also probes how to threshold confidence scores into predictions and how to handle zero-denominator edge cases.