Your model's scores rank things correctly but don't behave like probabilities. Isotonic regression fixes that by fitting the data with the least restrictive assumption there is: the fitted values must never go down as the score goes up. No straight line, no curve shape — just "non-decreasing".
The algorithm is called pool adjacent violators, and it's as literal as it sounds:
x. Start with every y as its own block, each holding one value.Task: write isotonic_fit(x, y) returning the fitted value for each point, in ascending x order, each rounded to 4 decimal places.
x values are distinct but not necessarily sorted — sort the pairs first.Watch the weights. Pooling two blocks of sizes 1 and 3 must not average their two values evenly — the second one speaks for three points and has to count three times as much, or the fit drifts.