← Learning guides

Worked tutorial · about 35 minutes

Prioritize errors using counts and rates together

Work through a fictional 160-case review, distinguish error volume from within-bucket failure rate, and choose an investigation under explicit assumptions.

Original editorial exercise · fictional practice data · checked 25 October 2026

A bucket with the highest failure rate need not contain the most errors. Your goal in this exercise is to choose one investigation from a fixed review of a notice-answering assistant. You will calculate both quantities, explain why two averages differ, and work through a proposed change that also creates regressions.

All counts are invented. They summarize an editorial exercise, not a measured model or customer system. The input stipulates that each reviewed case has one primary bucket and one binary pass/fail judgment. The four nonempty buckets partition 160 cases; the planned scanned-notice bucket has no reviewed examples.

1. Keep three quantities separate

bucket,reviewed,errors
simple_lookup,90,9
missing_fact,20,8
multiple_conditions,40,12
conflicting_update,10,5
scanned_notice,0,0

Write the denominator beside each number before converting it to a percentage. For multiple_conditions, the first value is 12 errors; its error rate is 12/40; its share of errors is 12/34. A case with several secondary tags would still appear once in this primary-bucket table.

The file gives aggregate counts rather than the 160 individual cases. Accept the stated partition for this exercise. In a real audit, retain case IDs so you can check that no case was omitted or counted in two primary buckets. Overlapping tags such as “contains a date” and “contains a number” cannot be added as though they were disjoint buckets.

2. Calculate the table and compare rankings

Complete the worksheet first. Put an unknown rate beside an empty bucket. Zero reviewed cases provide no evidence of a zero failure rate.

Show all bucket calculations
Counts and rates on fictional reviewed cases
Primary bucketErrors / reviewedError rateShare of 34 errors
Simple lookup9 / 9010%9/34 ≈ 26.47%
Missing fact8 / 2040%8/34 ≈ 23.53%
Multiple conditions12 / 4030%12/34 ≈ 35.29%
Conflicting update5 / 1050%5/34 ≈ 14.71%
Scanned notice0 / 0Unknown0/34 = 0% of observed errors; unsampled

By observed error count: multiple conditions, simple lookup, missing fact, conflicting update. By within-bucket rate: conflicting update, missing fact, multiple conditions, simple lookup. The unsampled bucket has a known observed error count of zero and no defined rate to rank.

3. Reconcile the overall rate with the bucket average

Add counts before dividing: 9 + 8 + 12 + 5 = 34 errors, and 90 + 20 + 40 + 10 = 160 reviewed cases. The overall error rate is 34/160 = 21.25%.

The simple average of the four observed bucket rates is (10% + 40% + 30% + 50%) / 4 = 32.5%. This gives each bucket equal weight, including the ten-case conflicting-update bucket and the ninety-case lookup bucket. It answers a different question.

To recover the overall rate from rates, weight each by its case count: (90 × 0.10 + 20 × 0.40 + 40 × 0.30 + 10 × 0.50) / 160 = 0.2125. Exclude the unsampled bucket from an average of observed rates rather than inserting an invented zero.

python prioritize_errors.py bucket_counts.csv

Save the downloads together before running the optional Python 3 checker. It reads the CSV, validates counts, and prints the rankings and exact fractions using only the standard library. The overall fraction is 17/80; the unweighted bucket average is 13/40. A zero-denominator rate is null.

Show the complete checker
"""Compute counts and exact rates for fictional, disjoint primary buckets."""
import argparse
import csv
import json
from fractions import Fraction
from pathlib import Path


def rate(numerator, denominator):
    if denominator == 0:
        return None
    value = Fraction(numerator, denominator)
    return {'fraction': str(value), 'percent': float(value * 100)}


def evaluate(path):
    with Path(path).open(encoding='utf-8-sig', newline='') as handle:
        rows = list(csv.DictReader(handle))
    names = [row['bucket'] for row in rows]
    if not names or len(names) != len(set(names)) or any(not name for name in names):
        raise ValueError('Bucket names must be nonempty and unique.')
    for row in rows:
        row['reviewed'] = int(row['reviewed'])
        row['errors'] = int(row['errors'])
        if not 0 <= row['errors'] <= row['reviewed']:
            raise ValueError('Require 0 <= errors <= reviewed in each bucket.')
    reviewed = sum(row['reviewed'] for row in rows)
    errors = sum(row['errors'] for row in rows)
    defined = [row for row in rows if row['reviewed'] > 0]
    unweighted = (sum((Fraction(row['errors'], row['reviewed']) for row in defined), Fraction())
                  / len(defined)) if defined else None
    return {
        'scope': 'Supplied fictional aggregate counts; disjoint buckets are an input assumption.',
        'reviewed': reviewed,
        'errors': errors,
        'overall_error_rate': rate(errors, reviewed),
        'unweighted_observed_bucket_average': None if unweighted is None else {
            'fraction': str(unweighted), 'percent': float(unweighted * 100)},
        'buckets': [
            {**row, 'error_rate': rate(row['errors'], row['reviewed']),
             'share_of_errors': rate(row['errors'], errors)} for row in rows
        ],
        'by_error_count': [row['bucket'] for row in sorted(rows, key=lambda r: (-r['errors'], r['bucket']))],
        'by_error_rate_defined_only': [row['bucket'] for row in sorted(
            defined, key=lambda r: (-Fraction(r['errors'], r['reviewed']), r['bucket']))],
        'unsampled_buckets': sorted(row['bucket'] for row in rows if row['reviewed'] == 0),
    }


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('counts')
    args = parser.parse_args()
    try:
        print(json.dumps(evaluate(args.counts), indent=2))
    except (ValueError, KeyError, OSError) as exc:
        parser.exit(2, f'Input error: {exc}\n')

4. Choose an investigation for a stated objective

For this exercise, assume equal error severity and equal investigation cost. You can investigate one bucket, and your objective is to address the largest number of errors in this fixed review. Under those assumptions, start with multiple conditions: it contains 12 errors, the largest count.

Read those twelve failing cases before proposing a fix. Separate omitted conditions, unsupported conditions, misunderstood questions and questionable labels. These are hypotheses to inspect, not causes established by the count table. One bucket can contain several mechanisms that need different changes.

If a change fixed all twelve errors and created no other errors, its largest possible reduction on this review would be 12/160 = 7.5 percentage points, leaving 22/160 = 13.75% errors. This is a ceiling under a hypothetical perfect fix. The table gives no evidence that such a fix exists or how much it would cost.

The 50% conflicting-update rate still deserves attention. It describes a high observed failure proportion in only ten cases. If those mistakes were more consequential, or the future traffic mix changed, a different priority could be justified. Those facts are absent here, so keep them as decision inputs to collect.

5. Count regressions in a proposed change

Consider a separate what-if: six existing multiple-condition errors become passes, while two previously correct lookup cases become errors. All 160 cases remain the same, and nothing else changes.

Show the net result

The new total is 34 − 6 + 2 = 30 errors. The error rate becomes 30/160 = 18.75%, a reduction of 4/160 = 2.5 percentage points. Counting only the six fixes would overstate the improvement.

Multiple-condition errors fall to 6/40 = 15%; lookup errors rise to 11/90 ≈ 12.22%. Both changed buckets belong in the report. This is scenario arithmetic, not an observed rerun or an estimated causal effect.

To evaluate an actual change, preserve case IDs and before/after judgments, review disputed labels, and compare paired outcomes. After using this review to develop the change, evaluate it on fresh held-out cases. Sample counts alone do not establish the future error rate, expected time saved, or user impact.

Practice the paired comparison with two fixed prompt candidates. If the judgment itself is difficult, try the supported-answer audit. For class-specific measures rather than general pass/fail buckets, continue to precision and recall.

Sources and scope

Google's classification metrics lesson explains denominators, undefined rates and the role of error costs when choosing metrics. Its dataset-splitting lesson explains the limits of repeatedly using evaluation data for development. Sources checked 25 October 2026. The buckets, counts, priority assumptions and what-if calculations are our original exercise.