MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / _compute_ece

Function _compute_ece

uncommon_route/decision/calibration.py:40–58  ·  view source on GitHub ↗
(evals: list[dict], temperature: float, buckets: int = 10)

Source from the content-addressed store, hash-verified

38
39
40def _compute_ece(evals: list[dict], temperature: float, buckets: int = 10) -> float:
41 if not evals:
42 return 0.0
43 cal = PlattCalibrator(temperature=temperature)
44 bucket_data: list[list[tuple[float, float]]] = [[] for _ in range(buckets)]
45 for item in evals:
46 conf = cal.calibrate(item["confidence"])
47 correct = 1.0 if item["correct"] else 0.0
48 idx = min(int(conf * buckets), buckets - 1)
49 bucket_data[idx].append((conf, correct))
50 ece = 0.0
51 total = len(evals)
52 for bucket in bucket_data:
53 if not bucket:
54 continue
55 avg_conf = sum(c for c, _ in bucket) / len(bucket)
56 avg_acc = sum(a for _, a in bucket) / len(bucket)
57 ece += abs(avg_conf - avg_acc) * len(bucket) / total
58 return ece
59
60
61def save_calibrator(cal: PlattCalibrator, path: Path) -> None:

Callers 1

fit_platt_from_evalsFunction · 0.85

Calls 3

calibrateMethod · 0.95
PlattCalibratorClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected