/** * Distribution shift panel: cohorts whose share of the evaluation population * diverges from the training mix, annotated with the recall gap so a shift * that also hurts quality stands out. */ import Box from '@mui/material/Box'; import Table from '@mui/material/Table'; import TableBody from '@mui/material/TableBody'; import TableCell from '@mui/material/TableCell'; import TableHead from '@mui/material/TableHead'; import TableRow from '@mui/material/TableRow'; import Typography from '@mui/material/Typography'; import { fmtCompact, getRunShift } from '../../services/megaeval'; import { usePoll } from '../../services/labeleval'; import { ErrorNote, LoadingBox, SectionCard, fmtPct } from '../labeleval/shared'; import { HeadCell } from '../help/InfoTip'; function gapColor(gap: number | null): string | undefined { if (gap === null) return undefined; const g = Math.abs(gap); if (g >= 0.1) return '#ef5350'; if (g >= 0.05) return '#ffa726'; return undefined; } export default function ShiftTab({ runId, refreshKey }: { runId: string; refreshKey: number }) { const shift = usePoll(() => getRunShift(runId), null, [runId, refreshKey]); const data = shift.data; return ( {shift.error ? : null} {shift.loading && !data ? : null} {data ? ( <> {data.method} · thresholds: min eval count {fmtCompact(data.thresholds.min_eval_count)}, relative change ≥{' '} {fmtPct(data.thresholds.rel_threshold)} {data.shifts.length === 0 ? ( No significant distribution shifts detected. ) : ( Eval count {data.shifts.map((s) => { const color = gapColor(s.recall_gap); return ( {s.cohort} {fmtPct(s.train_share)} → {fmtPct(s.eval_share)} 0 ? '#ffa726' : '#4fc3f7' }} > {s.relative_change > 0 ? '+' : ''} {Math.round(s.relative_change * 100)}% {fmtCompact(s.eval_count)} {fmtPct(s.cohort_recall)} vs {fmtPct(s.overall_recall)} {s.recall_gap === null ? '—' : `${(s.recall_gap * 100).toFixed(1)} pts`} ); })}
)} Highlighted rows are cohorts that are over-represented vs training and underperforming on recall — prime candidates for targeted data collection. ) : null}
); }