Rank your predictions from most confident to least. Average precision rewards you for putting the real hits near the top — and unlike accuracy, it never asks you to pick a cutoff.
The recipe is short:
Task: write average_precision(y_true, scores) returning that average, rounded to 4 decimal places.
y_true holds 1 for a real positive and 0 otherwise. scores are the model's confidences. No two scores tie.A ranking that puts every positive first scores exactly 1.0. Every negative you let slip above a positive drags it down.
Once your code passes every test, a reference solution shows up here so you can compare it with yours.