Compute and plot a precision–recall curve
MicrosoftData Scientist · Technical ScreenLast updated
This question evaluates understanding of binary classification evaluation metrics—precision, recall, precision–recall curves, and related summaries like Average Precision/AUPRC—within the Machine Learning domain and is relevant for Data Scientist roles.
Precision–Recall (PR) curve coding / evaluation
You are given a binary classifier’s outputs on a dataset:
y_true: array of true labels in ({0,1})y_score: array of predicted scores/probabilities (higher means more likely positive)
Tasks
- Define precision and recall.
- Describe how to compute the precision–recall curve by sweeping a decision threshold over
y_score. - Implement (in pseudocode or Python) a function that returns PR curve points:
- Output arrays:
thresholds,precision,recall
- Mention at least two edge cases/pitfalls (e.g., ties in scores, no predicted positives at a threshold, extreme class imbalance).
Optional: Explain how to compute Average Precision / AUPRC and what the baseline means.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.