Aggregating and interpreting metrics: a per-slice report instead of one average

Study time
≈ 2 h (estimate)
Needs
L2-M03-L04
Updated
2026-11-03

Progress is saved in this browser only. No account, nothing is sent to a server.

Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Module: L2-M03 · Duration: ~120 min (estimate, including the independent exercise) · Previous: L04 · Next: L2-M04-L01 (module LLM-as-a-Judge, not yet written)

1. Introduction

You now have metrics (L01-L02), a rubric (L03) and criteria (L04). The last step is to turn hundreds of grading results into a report that a decision-maker can read. The easiest way is one average: "the new version passes 91.8%". That number is true and almost useless, because it hides exactly where you need to look: a small but dangerous group of questions can get worse while everything else improves.

This lesson teaches three kinds of average; reporting by slice (a group of cases sharing one attribute, such as intent) with confidence intervals and a decision rule; Simpson's paradox, where a system wins in every slice yet loses when pooled; and two ways a metric gets gamed without anyone meaning to. The output is a per-slice report in place of one average, with a list of what that report does not say.

2. Learning objectives

  1. Compute the pooled average, the per-slice average and the weighted average, and explain when they differ. Practice: §8.2 part B and §8.3.
  2. Produce a per-slice report with sample size, confidence interval, threshold and the status of each slice. Practice: §8.2 part A.
  3. Detect a regression in one slice even when the average goes up. Practice: §8.2 part C, §8.3.
  4. Recognise Simpson's paradox in given numbers. Practice: §8.2 part D, §8.3.
  5. Check whether a metric can be gamed by a constant answer and read the trivial baseline. Practice: §8.2 part E, §8.3, §9.

3. Prerequisites and tools

  • L2-M01-L04 and L05: the Wilson interval, the SHIP, BLOCK, INCONCLUSIVE rule and sample size by risk level (the lab re-implements them briefly so it can run on its own).
  • L2-M02-L02: slices, weights by real distribution, the coverage matrix.
  • L2-M03-L01 to L04: precision, recall and the metric functions.
  • The code lab code-labs/l2-m03 (self-contained).

4. Concepts

4.1 Three kinds of average

With k passes out of n cases in each slice, there are three ways to combine. The pooled average (also called micro) is the total passes divided by the total cases: large slices dominate. The per-slice average (macro) is the arithmetic mean of the slices' rates: each slice has the same weight whether it has 10 or 100 cases. The weighted average is Σ (the slice's real share in the product) × (the slice's pass rate): it answers "what will real users see", provided you know the real shares (L2-M02-L02). The three numbers differ when slices differ in size and quality. A small example in the lab: three slices (9/10, 1/10, 0/80) give a pooled 1/10, a per-slice 1/3, and with weights 0.5, 0.25, 0.25 a weighted 19/40. All three are "right"; they answer three different questions, and the report must say which one. weighted also requires the weights to cover exactly the slices, be non-negative, and sum to 1 (compared with Fraction), and a slice with no cases raises an error, rather than being read as 0 or 1.

4.2 Slices and per-slice confidence intervals

The smaller the slice, the less certain the rate. The lab's report computes a 95% Wilson confidence interval for each slice (L2-M01-L04) and applies the rule of L2-M01-L05: SHIP if the whole interval is above the threshold, BLOCK if the whole interval is below, INCONCLUSIVE otherwise. There is one more status: TOO_FEW when a slice has fewer than min_n cases (the lab uses 30), which makes no decision whatever the interval says, because with small n a good or bad result can be down to luck. The per-slice thresholds follow from L2-M01: check and concept 0.95 (correctness, high risk), hint 0.90 (pedagogy, medium), offtopic 0.85 (scope, low), pii 0.98 (safety, high). These numbers are set by the lab.

An honest note: the sample size of each slice (45 to 140) is smaller than what L2-M01-L05 demands for a high-risk criterion (203 cases for threshold 0.95, margin ±0.03). So most statuses are INCONCLUSIVE, as L2-M01 predicted.

4.3 Simpson's paradox

When a population is split into subgroups, a relationship can appear, disappear or reverse; the Stanford Encyclopedia of Philosophy describes the phenomenon and says the cause is that the subgroups have different weights [R1]. In the lab (data/simpson_counts.json), system A passes 19/20 in the concept slice and 54/80 in the pii slice; system B passes 90/100 and 6/10. A wins in both slices (0.95 against 0.90; 0.675 against 0.60) but pooled A is 73/100 = 0.73 and B is 96/110 ≈ 0.873. The cause: A was evaluated on a set with many pii (hard) questions, B on a set with many concept (easy) questions. simpson_reversal(a, b) returns True when one system strictly wins in every shared slice yet strictly loses when pooled. So do not compare two systems by a pooled number on two sets with different composition: run both on the same set, or compare by slice.

5. Technical deep dive

5.1 The per-slice report: structure and decision

report.build_report(records, field, key, thresholds, weights, min_n) groups the records by key (here intent) and computes for each slice the passes, the cases, the rate, the Wilson interval, the threshold and the status; together with the pooled number, the weighted number and an overall verdict. The verdict rule: BLOCK if any slice is BLOCK; SHIP only if every slice is SHIP; otherwise INCONCLUSIVE (including TOO_FEW). One bad slice is enough to block; a good average cannot "buy it back".

In the report for v1 on 425 simulated cases (demo part A), three slices are BLOCK: check 88/100 = 0.880 (threshold 0.95), offtopic 28/45 = 0.622 (0.85) and pii 46/50 = 0.920 (0.98). Version v2 improves check, hint, offtopic; concept changes negligibly; and pii drops to 40/50 = 0.800.

5.2 Comparing two versions: per-slice regression

The pooled number for v1 is 0.868 and for v2 is 0.918. A one-line report would write "v2 is 5 percentage points better". But regressions(old, new) (which slices dropped by 0.05 or more, inclusive) returns exactly one slice: pii, down 0.12 (46/50 to 40/50). pii is a high-risk slice (safety) with the highest threshold. The verdict for v2 is still BLOCK because pii is BLOCK (interval 0.670 to 0.888, entirely below 0.98), while the other four slices are INCONCLUSIVE. A pooled number going up while a dangerous slice gets worse is normal when a change improves most things and hurts the rarely seen part.

Two things to record: (1) in the simulation we know that v2's true error probability on pii is higher than v1's (0.16 against 0.04 before the style factor, lab/system.py), so the regression is real; with a real system you do not know, and 50 cases could make a regression appear or vanish through luck; (2) checking whether the difference between two runs is statistically significant was covered in L2-M01-L04; L2-M07 goes deeper.

5.3 Gamed metrics: the trivial baseline and a skewed dataset

Goodhart's law says that when a measure becomes a target to optimise, it stops reflecting what we want. Manheim and Garrabrant analyse its mechanisms; according to the abstract, optimising a metric can stop helping or start causing harm when pushed too far, and the risk grows with the optimisation pressure aimed at the proxy measure [R2] (only the abstract was read, not the mechanisms). A skewed dataset makes a metric easy to game; Goodhart happens when someone, or a prompt-fixing loop, optimises against it.

The lab has 60 "check the student's work" cases (data/check_cases.jsonl): the student gives an answer and the tutor must say right or not yet right. verdict_of(reply) reads the conclusion: "negative" if there is a phrase such as "chưa đúng" (not yet right), "sai" (wrong); otherwise "positive" if there is "đúng rồi" (that's right), "chính xác" (exactly), "giỏi lắm" (well done) or just the word "đúng" (right); otherwise "none". verdict_ok(reply, student_correct) compares it with the truth. Of the 60 cases, 54 have a student who got it right. A "system" that says only "Đúng rồi em!" (That's right!) for every case reaches 54/60 = 0.900; the other constant reply, "Chưa đúng em ạ." (Not yet right.), reaches 0.100. Choose a balanced subset (6 right, 6 wrong) and both reach 0.500 (trivial_baseline, balanced).

A metric on which a system that does nothing still reaches 0.900 cannot tell a good system from a lazy one at that level. With a threshold of 0.85 and 60 cases, Wilson gives 54/60 as INCONCLUSIVE (not yet blocked, not yet approved), but 540/600 (the same rate of 0.900) gives SHIP (§8.3). A larger sample does not fix a skewed dataset; it only makes the wrong result more certain. The fix is a dataset with enough wrong cases (L2-M02) and reporting the trivial baseline next to the result.

5.4 A panel of metrics and lazy answers

A panel of several metrics can mask one another. The lab builds a panel of three cheap metrics (PANEL): concise (no more than 25 words), does not reveal the answer, and Vietnamese (contains accented letters). Running four constant answers (DEGENERATE: the empty string, "Em hãy thử lại nhé." (Please try again.), "Đúng rồi em!", "Chưa đúng em ạ.") through every case, degenerate_all_pass shows that 3 of 4 pass all three metrics on every case. The empty string is rejected because it has no accented letters. Add a fourth metric, verdict_ok, and no constant answer passes every case (the test test_lazy_replies_pass_a_panel_without_a_correctness_metric).

The lesson: a panel made of "does no harm" metrics (short, not revealing, the right language) can give a useless system a high score. Before trusting a panel, run the constant answers through it. Anthropic writes "Make your graders resistant to bypasses or hacks" and "The agent shouldn't be able to easily 'cheat' the eval", along with the advice to read the transcripts: "You won't know if your graders are working well unless you read the transcripts and grades from many trials" [R3]. OpenAI also warns that a model grader can be subject to "grader hacking" and advises comparing its results with expert judgement [R4].

6. The QA perspective

6.1 What lint_report does not check

lint_report(rep) checks that the report is not one average: it has at least two slices; each slice has n, a rate, an interval, a threshold and a status; each slice's n is positive; the sum of the slices' n equals the overall n; and it has the name of the definition version, the pooled number, the weighted number, the verdict and min_n. It does not know: whether the slice is the right one (a report by style still passes lint although intent is needed); whether the thresholds are reasonable; whether the weights match the product; whether the dataset is skewed (§5.3); whether the confidence interval applies when the cases are not independent (L2-M01-L04).

verdict_of from §5.3 also has a blind spot: "Đúng hướng rồi nhưng chưa đủ." ("Right direction but not enough yet.") is read as positive because no phrase in the negation list appears (test_verdict_reader_and_its_blind_spots pins that). A small human-reviewed sample is needed (L2-M05).

6.2 Interpretation rules and report contents

A usable report states: the name and version of the metric definitions (L01-L04); the dataset version (L2-M02); a per-slice table with n, rate, interval, threshold, status; the pooled number and the weighted number, with a sentence saying which question each answers; the slices that regressed against the previous version; the trivial baseline of each metric; and a limitations section: which slices are TOO_FEW, the blind spots of the checks, what was not measured. Reading rules: (1) the worst slice first; (2) draw no conclusion from a TOO_FEW slice; (3) a regression in a high-risk slice matters more than a rise in the average; (4) a pooled number is comparable only when two runs use the same dataset; (5) do not change a threshold after seeing the results. Do not write "passes 91.8%" without adding "the pii slice is BLOCK".

7. Real-world scenarios

Scenario 1 (fictional): "Up 5 points, ship". The HocVui Tutor team saw v2 beat v1 by 5 percentage points on the pooled number and wanted to ship. The per-slice report showed pii falling from 0.920 to 0.800 and the verdict was BLOCK. They kept the old version, investigated, and released v2 only once that slice was fixed and had enough cases to clear the threshold.

Scenario 2 (fictional): "90% while doing nothing". The team added a "correct conclusion" metric for the work-checking feature and saw the system reach 90%. Someone ran the constant reply "Đúng rồi em!" and also got 0.900, because 54 of the 60 students in the dataset had done it right. They added wrong-work cases until the set was balanced and from then on reported the trivial baseline next to the result.

8. Hands-on tutorial

8.1 Setup

cd academy-content/code-labs/l2-m03
python3 -m venv .venv && source .venv/bin/activate     # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest            # 63 passed

8.2 Run the demo

python -m lab.demo l05

Output (copied from a real run on Python 3.14.6 and 3.12.14, 2026-11-03; the two versions give identical output):

A. per-intent report, 425 cases (simulated), thresholds by risk
definition def-1  metric v1 by intent  n=425  min_n=30
slice          k/n   rate    95% Wilson   thr  status
check       88/100  0.880  0.802-0.930  0.95  BLOCK
concept     87/90   0.967  0.907-0.989  0.95  INCONCLUSIVE
hint       120/140  0.857  0.790-0.906  0.90  INCONCLUSIVE
offtopic    28/45   0.622  0.476-0.749  0.85  BLOCK
pii         46/50   0.920  0.812-0.968  0.98  BLOCK
pooled 0.868  weighted by production mix 0.856  verdict BLOCK
definition def-1  metric v2 by intent  n=425  min_n=30
slice          k/n   rate    95% Wilson   thr  status
check       94/100  0.940  0.875-0.972  0.95  INCONCLUSIVE
concept     86/90   0.956  0.891-0.983  0.95  INCONCLUSIVE
hint       131/140  0.936  0.882-0.966  0.90  INCONCLUSIVE
offtopic    39/45   0.867  0.738-0.937  0.85  INCONCLUSIVE
pii         40/50   0.800  0.670-0.888  0.98  BLOCK
pooled 0.918  weighted by production mix 0.917  verdict BLOCK
B. three averages of v2
   pooled 0.918  mean of slices 0.900  weighted by production mix 0.917
C. slices that lost at least 0.05 from v1 to v2: [('pii', '0.120')]
D. A beats B in every slice, pooled A 0.730 vs B 0.873: reversal True
E. constant replies on the verdict metric: 60 cases, 54 with a correct student answer
   'Đúng rồi em!'       all cases 0.900  balanced subset (12) 0.500
   'Chưa đúng em ạ.'    all cases 0.100  balanced subset (12) 0.500
   lazy replies that pass every metric of a 3-metric panel: 3 of 4

Reading the output:

  • A. Two reports; in v1 three slices are BLOCK (check, offtopic, pii), in v2 only pii is BLOCK and four slices are INCONCLUSIVE. The pooled and weighted figures are on the last line of each report.
  • B. The three kinds of average of v2 differ: 0.918, 0.900, 0.917.
  • C. Only pii lost 0.05 or more: 0.120.
  • D. A wins every slice but pooled it is 0.730 against B's 0.873.
  • E. "Đúng rồi em!" reaches 0.900 on the whole set and 0.500 on the balanced set; 3 of 4 lazy answers pass the whole three-metric panel.

8.3 Try it yourself

Save it as try_l05.py in the lab's root folder (next to lab/), run python try_l05.py, then delete the file:

from fractions import Fraction
from lab import report

counts = {"a": (9, 10), "b": (1, 10), "c": (0, 80)}
print(report.micro(counts), report.macro(counts), report.weighted(counts, {"a": "0.5", "b": "0.25", "c": "0.25"}))
print(report.decide(27, 30, 0.9), report.decide(54, 60, 0.85), report.decide(540, 600, 0.85), report.decide(50, 50, 0.9))
print(report.verdict_of("Em làm đúng hướng, nhưng 6 nhân 4 là 25."))
try:
    report.weighted({"a": (0, 0), "b": (1, 2)}, {"a": 0.5, "b": 0.5})
except ValueError as e:
    print("ValueError:", e)

# own numbers: A beats B in every slice but loses when pooled
a = {"e": (18, 20), "h": (30, 80)}
b = {"e": (85, 100), "h": (3, 10)}
print(report.micro(a), report.micro(b), report.simpson_reversal(a, b))

# a constant reply on three cases (two correct students, one wrong)
cases = [{"student_correct": True}, {"student_correct": True}, {"student_correct": False}]
print(report.trivial_baseline(cases, "Đúng rồi em!"))

# which slices lost at least 0.05?
old = {"rows": [{"slice": "a", "rate": Fraction(9, 10)}, {"slice": "b", "rate": Fraction(1, 2)}]}
new = {"rows": [{"slice": "a", "rate": Fraction(9, 10)}, {"slice": "b", "rate": Fraction(2, 5)}]}
print(report.regressions(old, new))

Output (identical on Python 3.14.6 and 3.12.14):

1/10 1/3 19/40
INCONCLUSIVE INCONCLUSIVE SHIP SHIP
positive
ValueError: a slice has no cases
12/25 4/5 True
2/3
[('b', Fraction(1, 10))]

Reading: the three averages 1/10, 1/3, 19/40; 54/60 is INCONCLUSIVE while 540/600 is SHIP at the same threshold of 0.85; a sentence with a wrong result but containing the word "đúng" is read as positive (a blind spot of verdict_of); a slice with no cases raises an error. The last three lines are our own numbers: A beats B in both slices but pooled it is 12/25 against 4/5 (True: Simpson); the constant reply "Đúng rồi em!" reaches 2/3 on three cases with two students who got it right; slice b dropped by 1/10, from 1/2 to 2/5.

8.4 Run the lesson's tests

python -m pytest tests/test_l05_report.py -v

Result: 11 passed. Read test_the_average_improves_while_a_high_risk_slice_regresses and test_constant_reply_baselines_expose_an_unbalanced_dataset.

8.5 Troubleshooting

Symptom Cause Fix
ValueError: weights cover [...] but slices are [...] The weights are missing or have extra slices Use weights for exactly the slices present in the data
ValueError: weights must be non-negative and sum to 1 The weights do not sum to 1 Use strings such as "0.3" to avoid float error
The report is all TOO_FEW Every slice is below min_n Collect more cases; do not lower min_n to get a status

9. Independent exercise

Problem: Read the per-slice reports of two candidate versions A and B and make a decision, then find out why a high threshold needs many cases.

Requirements: complete exercises/test_l05_report.py:

  1. TODO 1: fill in VERDICT_A and VERDICT_B (one of "SHIP", "BLOCK", "INCONCLUSIVE") from the report by intent with min_n = 30, field ok.
  2. TODO 2: fill in BLOCKING_SLICES_A: the names of the slices (sorted) with status BLOCK for candidate A.
  3. TODO 3: fill in A_BEATS_B_POOLED (True or False): is A's pooled number higher than B's?
  4. TODO 4: fill in N_FOR_098: the smallest n such that n passes out of n cases gives decide(n, n, 0.98) == "SHIP".
  5. TODO 5: write the decision passage (see Deliverable).

Test data: exercises/runs_a.jsonl and exercises/runs_b.jsonl (300 simulated cases each, {id, intent, ok}), thresholds and weights from data/.

Deliverable: the four groups of variables, and a decision passage at the end of the file exercises/test_l05_report.py: a comment line starting with # DECISION: (and the comment lines after it) saying what you decide for A and why, at least 25 words long.

Acceptance criteria: python -m pytest exercises/test_l05_report.py passes (4 tests, including test_decision_comment_exists, which reads the file itself and requires a # DECISION: passage of at least 25 words). The test only counts words; whether the reasoning is right is for a reviewer to judge.

Hint: use report.build_report and then report.render to read both reports side by side, and read the worst slice first. For TODO 4, try a few values of n before writing a loop. If you choose B, how many more cases are needed in which slice to be able to SHIP?

10. Knowledge check

0/18 done · Results are kept in this browser only.

P02 · True or false

If system A beats system B on every shared slice, then A's pooled number is also higher than B's.

P04 · Select all that apply

In the report of v1 (425 cases, min_n = 30), which slices have status BLOCK? Select all that apply.

P05 · Put in order

Put in order the steps build_report takes to produce a report by slice (§5.1).

  1. Group the records by slice (here intent)
  2. Compute the pass count, the case count, the rate and the Wilson interval for each slice
  3. Compute the pooled number and the weighted number
  4. Derive the overall verdict: BLOCK if any slice is BLOCK, SHIP only if every slice is SHIP
  5. Compare with the slice's threshold and assign a status (TOO_FEW if n is smaller than min_n)

P06 · Match

Match each kind of average or measure with the question it answers.

P07 · Spot the bug

The function below is meant to compute the overall verdict from the slice statuses, but a BLOCK slice can be ignored. Find the bug.

def release_verdict(rows, pooled):
    if any(r["status"] == "BLOCK" for r in rows) and pooled < 0.9:
        return "BLOCK"
    if all(r["status"] == "SHIP" for r in rows):
        return "SHIP"
    return "INCONCLUSIVE"

P08 · Short answer

Write a three-to-four-sentence summary of the v2 report to send to the decision maker, so that nobody reads it as "v2 is better".

P09 · Essay

A panel of three metrics (short, at most 25 words; does not reveal the answer; has Vietnamese letters with diacritics) gives a high score to the constant reply "Em hãy thử lại nhé." ("Try again, dear.") on every case. Write 5-8 sentences: why that panel cannot measure quality, how you check that, and what you add to the panel.

P10 · Recall

Lesson: L2-M01-L04

By the decision rule of L2-M01-L04 §5.2, what does decide(90, 100, 0.90) return, and what is the right next action?

P11 · Recall

Lesson: L2-M02-L02

By L2-M02-L02 §5.3, why is the weighted number of v1 (0.856) lower than the pooled number (0.868)?

P12 · Multiple choice

Two systems are graded on two sets with different mixes. Slice x: A passes 9/10, B passes 70/90. Slice y: A passes 20/90, B passes 1/10. Pooled: A is 29/100 and B is 71/100. What is the right conclusion?

P13 · Fill in the blank

Among 60 homework-checking cases (54 where the student was right), the constant reply "Chưa đúng em ạ." ("Not right yet.") passes ___ on the whole set. On a balanced set of 12 cases (6 right, 6 wrong), both constant replies "Đúng rồi em!" ("That is right!") and "Chưa đúng em ạ." pass ___. With a threshold of 0.85, decide(540, 600, 0.85) (the same rate 0.900 as 54/60) is ___.

P14 · True or false

If a metric gives a lazy system 0.900 on a set of 60 cases, collecting 540 more cases with the same mix will make that metric more trustworthy.

P15 · Select all that apply

lint_report checks that a report is not a single average. Select everything it does not know.

P16 · Multiple choice

The student was right and the tutor replies "Không sai đâu em." ("It is not wrong, dear."). What happens with verdict_of and verdict_ok(reply, True)?

P17 · Multiple choice

Four constant replies (the empty string, "Em hãy thử lại nhé.", "Đúng rồi em!", "Chưa đúng em ạ.") are run through the three-metric panel (short, does not reveal the answer, has letters with diacritics) on 60 cases. What is the right result?

11. Summary

  • Concepts: three kinds of average answer three different questions; a per-slice report has sample sizes, intervals and statuses; the verdict is BLOCK when any slice is BLOCK; Simpson reverses the order when the sets differ in composition; the trivial baseline measures dataset skew.
  • Skills: building a per-slice report; detecting regressions; running constant answers through a metric and a panel.
  • Traps: one average; comparing pooled numbers on two sets with different composition; trusting a "does no harm" panel; thinking a larger sample fixes a skewed dataset; lowering a threshold or min_n after seeing the results.
  • You can now: take a number "passes X%" and ask five questions: which slice, how many cases, which threshold, how much is the trivial baseline, which version of the metric definition.

12. References

ID Title Publisher URL Accessed Relevance
R1 Simpson's Paradox Stanford Encyclopedia of Philosophy https://plato.stanford.edu/entries/paradox-simpson/ 2026-11-03 Definition and cause (different group weights) (read 100,000 of 112,591 characters)
R2 Categorizing Variants of Goodhart's Law (Manheim, Garrabrant) arXiv https://arxiv.org/abs/1803.04585 2026-11-03 Abstract-only: optimising a metric can stop helping; the four mechanisms were not read
R3 Demystifying evals for AI agents Anthropic https://www.anthropic.com/engineering/demystifying-evals-for-ai-agents 2026-11-03 Graders resistant to bypasses; reading the transcripts of many runs
R4 Graders (caveats) OpenAI https://developers.openai.com/api/docs/guides/graders 2026-11-03 Warning about grader hacking; comparing with expert judgement

Key terms (English ↔ Vietnamese)

English Tiếng Việt
Slice Lát cắt (nhóm case chung một thuộc tính)
Pooled (micro) average Trung bình gộp
Macro average Trung bình theo lát
Weighted average Trung bình có trọng số (theo tỷ lệ thật)
Simpson's paradox Nghịch lý Simpson
Regression (between versions) Hồi quy: lát xấu đi giữa hai phiên bản
Verdict Quyết định tổng (SHIP, BLOCK, INCONCLUSIVE)
Too few (TOO_FEW) Quá ít case để quyết định
Trivial baseline Baseline tầm thường
Goodhart's law Định luật Goodhart (tối ưu hóa quá mức một số đo thì nó thôi giúp ích)
Panel (of metrics) Bảng metric