Precision-Recall Curve Calculation
Core Metrics DS practice problem on Onlearn.
Difficulty: medium.
Topics: Precision-Recall Curve Calculation, True Positive Rate, Positive Predictive Value, Area Under Curve, Classification Threshold, Confusion Matrix, Supervised Learning, Model Evaluation, Statistical Inference, Information Theory, Decision Theory, Binary Classification, Performance Metrics, Threshold Optimization, Probabilistic Modeling, Error Analysis.
Implement a function that computes the precision recall curve for binary classification. Given true binary labels and predicted probability scores, your function should calculate precision and recall values at different decision thresholds. For each unique threshold (sorted in descending order), samples with scores greater than or equal to the threshold are classified as positive. Compute the precision (true positives / predicted positives) and recall (true positives / actual positives) at each threshold. The function should return three lists: 1. Precisions at each threshold 2. Recalls at each threshold 3. The threshold values used (unique scores in descending order) Handle edge cases appropriately: When there are no predicted positives at a threshold, precision should be 1.0 When there are no actual positives in the data, recall should be 0.0