TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

170. Expected Calibration Error

Medium

Given per-sample predicted-class confidences, predicted classes, and true labels, compute ECE with equal-width binning.

Signature: def ece(confidences: list, predictions: list, labels: list, n_bins: int = 10) -> float

  • Split [0, 1] into n_bins equal-width bins.
  • For each bin: gap = | accuracy - mean_confidence | * (bin_count / N)
  • Sum gaps across bins. Empty bins contribute 0.

The last bin should be inclusive on the right edge (so confidence == 1.0 falls into the last bin, not outside).

Math

ECE=b=1∑B​N∣Bb​∣​​acc(Bb​)−conf(Bb​)​

Asked at

NumPy

import numpy as np

 

def ece(...):

    pass

🔒

Premium problem

Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.

Upgrade to PremiumBack to problems

Already premium?