Compute Precision, Recall, and F1
Problem Description
You are provided with a dataset consisting of binary classification outputs. Each record in the dataset represents a single prediction and contains the following fields:
actual: An integer, either0or1, representing the true label.predict: An integer, either0or1, representing the model's predicted label.conf: A float, indicating the model's confidence score for the positive class (1).
An example record might look like: [actual=1, predict=0, conf=0.93].
Task
Your task is to write Python code or pseudocode to compute the following classification metrics for the positive class (1) across the entire dataset:
- Precision
- Recall
- F1 Score
Additionally, you must explain:
- How to derive the
predictlabel from theconfscore if the interviewer requests applying a custom threshold instead of using the providedpredictlabels. - Strategies for handling edge cases where a denominator in any of the metric calculations becomes zero.
AI interview prep
Core dilemma
Ensuring statistical rigor and practical robustness in the calculation of classification metrics, especially when confronted with edge cases and the need to adapt to varying business objectives through thresholding.
2 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Compute Precision, Recall, and F1
Problem Description
You are provided with a dataset consisting of binary classification outputs. Each record in the dataset represents a single prediction and contains the following fields:
actual: An integer, either0or1, representing the true label.predict: An integer, either0or1, representing the model's predicted label.conf: A float, indicating the model's confidence score for the positive class (1).
An example record might look like: [actual=1, predict=0, conf=0.93].
Task
Your task is to write Python code or pseudocode to compute the following classification metrics for the positive class (1) across the entire dataset:
- Precision
- Recall
- F1 Score
Additionally, you must explain:
- How to derive the
predictlabel from theconfscore if the interviewer requests applying a custom threshold instead of using the providedpredictlabels. - Strategies for handling edge cases where a denominator in any of the metric calculations becomes zero.