Measure probability quality and calibration bins
Implement calibration_report(probabilities, labels, bins=5). Require equal nonempty lengths, finite numeric probabilities in [0,1] excluding booleans, integer labels 0 or 1 excluding booleans, and a positive integer bin count. Use equal-width bins [i/bins,(i+1)/bins), with probability 1 in the last bin. Return brier, ece, and bin_stats containing index, count, mean_probability, event_rate for nonempty bins only. ECE is the sample-weighted absolute difference between mean event probability and observed event rate.
Your task
- Complete the starter function using the contract above.
- Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
- Run tests to record your result, then compare with the explained reference solution.
Examples
Inputprobabilities=[0,1], labels=[0,1], bins=2
Outputbrier=0.0, ece=0.0, two nonempty bins
Inputprobabilities=[0.8,0.8,0.8], labels=[1,1,0], bins=5
Outputbrier=0.24, ece about 0.133333
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor