A precision-recall curve needs a summary number for comparing models. Average precision (AP) is the area under that curve, computed as a step function: each time recall increases, add the precision at that point, weighted by how much recall increased. It rewards putting positives near the top of the ranking, and it is far more informative than ROC AUC when positives are rare.
Implement average_precision(y_true, scores) for binary labels, where higher score means more likely positive (label 1).
ValueError.ValueError.Open one at a time. Each gives away a little more than the last.
np.argsort(-scores, kind="stable") orders the rows, and np.cumsum over the sorted labels gives TP at every row.
Keep only the positions where the sorted score changes, plus the last position. np.diff(sorted_scores) != 0 finds the changes.
No results yet
Run your code to check it against the examples, or submit to run every test.