ROC Curve Calculation
Core Metrics DS practice problem on Onlearn.
Difficulty: medium.
Topics: ROC Curve Calculation, True Positive Rate, False Positive Rate, Area Under the Curve, Youden's J Statistic, Probability Thresholding, Statistical Learning Theory, Model Evaluation & Selection, Probability & Statistics, Information Theory, Decision Theory, Binary Classification Metrics, Threshold-Independent Analysis, Performance Visualization, Cost-Sensitive Learning, Model Calibration.
Implement a function to compute the Receiver Operating Characteristic (ROC) curve for binary classification. Given ground truth binary labels and predicted scores/probabilities, your function should compute the False Positive Rate (FPR) and True Positive Rate (TPR) at various classification thresholds. The ROC curve is created by evaluating the classifier at different thresholds, starting from a threshold that classifies nothing as positive (giving the point (0,0)) and decreasing until everything is classified as positive (giving the point (1,1)). Your function should: 1. Consider each unique score value as a potential threshold 2. For each threshold, classify samples with scores = threshold as positive 3. Compute TPR and FPR at each threshold 4. Return the FPR and TPR values as lists The function should handle edge cases where all samples belong to one class.