How expected calibration error is computed
The formula. Sort every prediction into M bins by its predicted probability. For each bin B, take the mean predicted probability (confidence) and the fraction of rows whose label is 1 (accuracy for the positive class). Guo et al. (2017) define ECE = sum over bins of |B|/n times |acc(B) - conf(B)|, so each bin's gap is weighted by how many predictions it holds. MCE is simply the largest gap in any non-empty bin.
Worked example. The default 20 rows with 10 uniform bins give bins such as [0.2, 0.3] holding 0.25, 0.30 and 0.30: mean confidence 0.2833, fraction positive 0.6667, gap 0.3833, weight 3/20. Summing all ten weighted gaps gives ECE = 0.2015, and the largest gap, 0.45 in the (0.4, 0.5] bin, is the MCE. These numbers match scikit-learn 1.7.1 output in our unit tests.
Edge rules. A probability exactly on an inner edge such as 0.3 falls in the lower bin, and 1.0 falls in the last bin, which is how calibration_curve assigns bins with searchsorted.