import { scaleLinear } from 'd3-scale'; import type { BacktestReport } from '@/lib/types'; const W = 360; const H = 360; const M = 34; /** Calibration plot: predicted probability (x) vs observed frequency (y). Points * on the diagonal = perfectly calibrated. Dot size ∝ sample count. */ export function ReliabilityDiagram({ reliability, ece }: { reliability: BacktestReport['reliability']; ece: number }) { const sx = scaleLinear().domain([0, 1]).range([M, W - 8]); const sy = scaleLinear().domain([0, 1]).range([H - M, 8]); const maxCount = Math.max(...reliability.map((b) => b.count), 1); const pts = reliability.filter((b) => b.count > 0); return (
Points hug the diagonal — when the model says 30%, it happens about 30% of the time. Calibration error (ECE) is just {ece.toFixed(2)} (lower is better; under 0.05 is excellent).