Build a Precision-Recall Curve
Problem statement
Given equal-length arrays scores and labels, compute precision and recall after each distinct score threshold.
Each label is 0 or 1. Process thresholds in descending score order. All observations with the same score must enter the predicted-positive set together. Return a two-row matrix: row 0 contains precision values and row 1 contains recall values. If there are no positive labels, every recall value is 0.
Function
precisionRecallCurve(scores: double[], labels: int[]) → double[][]Examples
Example 1
scores = [0.9,0.8,0.7,0.1]labels = [1,0,1,0]return = [[1.0,0.5,0.6666666666666666,0.5],[0.5,0.5,1.0,1.0]]Adding examples from highest to lowest score produces cumulative (TP,FP) counts of (1,0), (1,1), (2,1), and (2,2).
Example 2
scores = [0.9,0.9,0.2]labels = [1,0,1]return = [[0.5,0.6666666666666666],[0.5,1.0]]The two observations scoring 0.9 enter together, so the first point is computed after both tied scores are included.
Constraints
1 <= scores.length = labels.length <= 1000000.0 <= scores[i] <= 1.0, and every score is finite.labels[i]is0or1.- Answers are accepted within
10^-9absolute error.