PythiloLesson 6 of 12 · progress kept in this browser

Practice in Lab: Pool adjacent violations in weighted isotonic calibration →

Pool adjacent violations in weighted isotonic calibration

An isotonic calibrator learns a nondecreasing mapping from scores to event probability. Sorting labels alone does not solve the constrained fit: a low-scored positive can force several neighboring score groups to pool. Weighted pool-adjacent-violators preserves each block's total observation weight and positive weight, which yields the least-squares block mean. Tied scores must share one fitted value before later merging. This exercise returns explicit calibration blocks so a reviewer can inspect their boundaries, support and probability estimates.

blocks = [[0.,0.,1.,1.],[1.,1.,3.,0.]]
left, right = blocks
weight = left[2] + right[2]
positive = left[3] + right[3]
print([left[0], right[1], positive/weight])
Your task

Combine equal finite scores before fitting. Each tied score starts one block with total positive weight and total weight. Visit ascending scores and merge adjacent blocks while their positive-weight ratios decrease. Return [minimum_score, maximum_score, fitted_probability] per remaining block. Require aligned nonempty scores, binary integer labels and strictly positive finite weights. Keep equal neighboring fitted probabilities as separate blocks unless a decrease triggers a merge.