Machine Learning β€Ί Evaluation and Interpretation β€Ί Day 181

Day 181: Baselines and Error Analysis

Day 181 of 365 β€” Baselines and Error Analysis

Master the disciplined methodology of Baseline Benchmarking and Data-Centric Error Analysis: establish strict multi-tier baselines (Dummy, Domain Heuristic, Linear), manually audit and tag misclassified failure modes, compute Andrew Ng's Error Reduction Ceilings, and uncover hidden failure modes across operational and demographic data slices.

Course
Machine Learning
Category
Evaluation and Interpretation
Reading time
β‰ˆ 50 min
Practical time
β‰ˆ 60 min
Lesson duration
1h 50m
Last verified
2026-08-29

Hands-on lab for this lesson

Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/machine-learning/day-181-baselines-and-error-analysis

  1. Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
    git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git
    cd ai-roadmap-365.github.io
  2. Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path β€” section / subsection / week / day:
    cd labs/sections/machine-learning/day-181-baselines-and-error-analysis
  3. Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work β€” read it before running anything.
  4. Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
    bash tests/run_tests.sh   # or the test command named in the lab README

You can also open the lab as a local page (works offline, shows the file tree and expected output).

Learning objectives

By the end of this lesson you will be able to:

Prerequisites

Why this matters

When an applied machine learning project underperforms, inexperienced engineering teams reflexively enter an endless loop of Model-Centric Trial-and-Error:

After three weeks of wasted compute, test performance improves by a statistically meaningless +0.15%.

Meanwhile, experienced machine learning engineers follow a completely different discipline pioneered by Andrew Ng: Systematic Baselines and Data-Centric Error Analysis.

Instead of guessing algorithms, they establish strict multi-tier performance baselines to prove whether machine learning is even necessary. Then, they sit down and manually inspect 100 misclassified validation examples. They discover that:

By calculating the Error Reduction Ceiling, they prove that fixing label noise will yield an immediate +4.0% accuracy gain in one afternoon, while tweaking neural network hyperparameters would never exceed +0.2%.

In this lesson, you will master the four-tier baseline hierarchy, the rigorous methodology of manual error analysis, Andrew Ng’s error ceiling formulas, and slice-based subpopulation auditing.


The idea in plain language

Imagine a hospital emergency room that hires a software contractor to build an AI diagnostic tool predicting whether incoming patients need immediate critical care:

If the expensive AI cannot beat the nurse’s simple rule, it has no business being deployed in the hospital.

Furthermore, when the AI makes mistakes, you must open the medical charts of those specific patients (Error Analysis) and ask: Why did it fail? Was the thermometer broken? Was the patient pediatric?

You fix the root cause in the data, not by adding more layers to the neural network.


Historical background

The shift from Model-Centric tweaking to Systematic Error Analysis represents a major milestone in industrial AI:

  1. 2000s (The Kaggle Paradigm): Academic and competitive machine learning prioritized squeezing fractions of a percent by ensembling dozens of complex models on static, clean benchmark datasets (ImageNet, UCI).
  2. 2016–2018 (Andrew Ng & Coursera Deep Learning Specialization): Andrew Ng codified the practical engineering rules of error analysis in Machine Learning Yearning, demonstrating how Fortune 500 AI teams save months of engineering time by computing error ceilings.
  3. 2019 (Stanford Snorkel & Slice-Based Learning): Researchers formalized slice-based evaluation, showing that high-performing vision and NLP models regularly suffer from catastrophic blind spots on critical minority data slices.
  4. 2021 (The Data-Centric AI Movement): Andrew Ng launched the Data-Centric AI initiative, proving that in 80% of industrial use cases, fixing dataset errors, inconsistent annotations, and missing features produces 10x greater performance gains than changing model architectures.

Today, baseline benchmarking and slice auditing are foundational requirements in modern MLOps governance.


What it is β€” and what it is not

Let us establish precise definitions:

What it IS:

What it is NOT:


Why it was created and what problems it solves

Baselines and Error Analysis was created to resolve fundamental diagnostic and operational bottlenecks in machine learning pipelines.

How it works

Let us trace the algorithmic and procedural execution flow step by step.

The Four-Tier Baseline Performance Ladder

Before writing complex machine learning models, every project must establish the Four-Tier Baseline Ladder:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   THE FOUR-TIER BASELINE LADDER                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Tier   β”‚ Baseline Name               β”‚ Description                     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Tier 1 β”‚ Trivial Statistical Floor   β”‚ DummyClassifier (Majority Class)β”‚
β”‚        β”‚                             β”‚ DummyRegressor (Mean / Median)  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Tier 2 β”‚ Domain Heuristic / Rule     β”‚ Simple expert business logic    β”‚
β”‚        β”‚                             β”‚ (e.g. IF DTI > 45% THEN Reject) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Tier 3 β”‚ Simple Linear Model         β”‚ Logistic Regression with L2 /   β”‚
β”‚        β”‚                             β”‚ Ridge Regression                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Tier 4 β”‚ Complex ML Candidate        β”‚ XGBoost / LightGBM / ResNet     β”‚
β”‚        β”‚                             β”‚ (Must justify complexity lift!) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Tier 1: Trivial Statistical Baseline (DummyClassifier / DummyRegressor)

Tier 2: Domain Heuristic / Business Rule Baseline

Tier 3: Simple Linear Baseline

Tier 4: Complex Machine Learning Model


Andrew Ng’s Systematic Error Analysis Methodology

When your candidate model fails to meet business goals, follow this 4-step data-centric protocol:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   ANDREW NG ERROR ANALYSIS WORKFLOW                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1. Extract 100-500 misclassified validation examples: (y_true != y_predβ”‚
β”‚ 2. Create a Spreadsheet / Annotation Table with failure category tags  β”‚
β”‚ 3. Manually inspect each row and tag root-cause categories             β”‚
β”‚ 4. Compute the Error Reduction Ceiling for each category               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Formulating the Error Reduction Ceiling

Let N_val be the total number of validation samples, and let E_total be the total number of errors made by the baseline model:

E_total = sum(I(y_i != y_hat_i))

Let E_cat be the count of errors attributed to category k (e.g. Label Noise, Blurry Image, Missing Unit).

  1. Percentage of Total Errors: % of Errors_cat = (E_cat / E_total) * 100%

  2. Maximum Achievable Accuracy Gain (Error Reduction Ceiling): Max Accuracy Gain = (E_cat / N_val) * 100%

The Engineering Decision Matrix:

Error CategoryError Count (E_cat)% of ErrorsMax Accuracy GainEngineering FeasibilityAction
Label Noise45 / 10045.0%+4.5%High (Relabeling script)PRIORITY 1: Fix immediately
Missing Zip Code30 / 10030.0%+3.0%High (Add IP geolocation)PRIORITY 2: Add fallback feature
Rare Ambiguous Dialect5 / 1005.0%+0.5%Very Low (Months of audio collection)IGNORE: Not worth ROI

Slice-Based Performance Auditing

A model with 92% overall accuracy can conceal disastrous performance on specific business segments:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   SLICE-BASED PERFORMANCE AUDIT                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Subpopulation Slice  β”‚ Sample Count  β”‚ Error Count    β”‚ Error Rate     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Device: iOS          β”‚ 600           β”‚ 24             β”‚ 4.0% (Great)   β”‚
β”‚ Device: Android      β”‚ 400           β”‚ 120            β”‚ 30.0% (Broken!)β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Tier: Free Users     β”‚ 800           β”‚ 40             β”‚ 5.0% (Great)   β”‚
β”‚ Tier: VIP Enterprise β”‚ 200           β”‚ 80             β”‚ 40.0% (Fatal!) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

In the example above, the aggregated 85.6% accuracy hides the fact that the model fails on 40% of VIP Enterprise customers and 30% of Android devices. Deploying this model would destroy high-value enterprise revenue.


An everyday analogy

Think of a Formula 1 racing team testing a new car:

  1. Tier 1 Baseline (Walking): Proves the car moves forward.
  2. Tier 2 Baseline (Standard Road Car): Proves the racing car is faster than a family sedan.
  3. Tier 3 Baseline (Last Year’s Racing Car): Proves the new car is faster than the previous season’s vehicle.
  4. Error Analysis (The Telemetry Audit): The car is 1.5 seconds too slow per lap.
    • The engineers do not blindly replace the entire engine (Model-Centric Trial).
    • They look at telemetry data (Error Analysis) and find that 80% of lost time occurs during braking in Turn 4 due to tire pressure.
    • They adjust tire pressure (Data-Centric Fix) and win the Grand Prix.

Examples in practice

Let us visualize the Four-Tier Baseline Performance Ladder:

Diagram showing the 4-tier model performance comparison ladder from trivial statistical baselines up to complex deep architectures.

Below is the execution flow of Andrew Ng’s Systematic Error Analysis Workflow:

Animated flow chart detailing the data-centric error analysis workflow from error sampling to ceiling calculation and prioritization.

Let us examine real Python code implementing baseline comparisons, error slice auditing, and ceiling calculations:

import numpy as np
import pandas as pd
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.metrics import accuracy_score, f1_score

# 1. Simulate E-Commerce Churn Benchmark (n=1000)
rng = np.random.default_rng(42)
n_samples = 1000

# 90% Non-Churn, 10% Churn (Severe Imbalance)
y = rng.binomial(1, 0.10, size=n_samples)

# Features: Tenure, Monthly Spend, Support Tickets
X = np.column_stack([
    rng.exponential(12, size=n_samples),
    rng.normal(50, 15, size=n_samples),
    rng.poisson(1.5, size=n_samples) + (y * 3.0) # Support tickets correlate with churn
])

X_train, X_test = X[:800], X[800:]
y_train, y_test = y[:800], y[800:]

# 2. Evaluate Baseline Hierarchy
# Tier 1: Dummy Majority
dummy = DummyClassifier(strategy="most_frequent").fit(X_train, y_train)
dummy_acc = accuracy_score(y_test, dummy.predict(X_test))

# Tier 2: Domain Rule ("If support tickets > 3, predict Churn")
rule_pred = (X_test[:, 2] > 3).astype(int)
rule_acc = accuracy_score(y_test, rule_pred)
rule_f1 = f1_score(y_test, rule_pred)

# Tier 3: Linear Logistic Regression
linear = LogisticRegression().fit(X_train, y_train)
linear_pred = linear.predict(X_test)
linear_acc = accuracy_score(y_test, linear_pred)
linear_f1 = f1_score(y_test, linear_pred)

# Tier 4: Gradient Boosting Ensemble
gbdt = GradientBoostingClassifier(n_estimators=100, random_state=42).fit(X_train, y_train)
gbdt_pred = gbdt.predict(X_test)
gbdt_acc = accuracy_score(y_test, gbdt_pred)
gbdt_f1 = f1_score(y_test, gbdt_pred)

print("=== Baseline Performance Ladder ===")
print(f"Tier 1 (Dummy Majority):    Accuracy = {dummy_acc:.4f} | F1 = 0.0000")
print(f"Tier 2 (Domain Rule):        Accuracy = {rule_acc:.4f} | F1 = {rule_f1:.4f}")
print(f"Tier 3 (Logistic Baseline):  Accuracy = {linear_acc:.4f} | F1 = {linear_f1:.4f}")
print(f"Tier 4 (GBDT Candidate):     Accuracy = {gbdt_acc:.4f} | F1 = {gbdt_f1:.4f}")
print(f"GBDT Lift over Domain Rule:  {gbdt_f1 - rule_f1:+.4f} F1 Score")

# 3. Andrew Ng Error Analysis on GBDT Errors
errors_mask = (y_test != gbdt_pred)
total_errors = np.sum(errors_mask)
print(f"\nTotal Validation Errors: {total_errors} / {len(y_test)}")

# Categorize errors (Simulated manual inspection)
error_categories = {
    "Ambiguous Support Logs": 8,
    "New Account Zero History": 6,
    "Label Noise / Annotation Error": 4
}

print("\n=== Error Reduction Ceiling Analysis ===")
for cat, count in error_categories.items():
    pct_errors = (count / total_errors) * 100.0
    max_acc_gain = (count / len(y_test)) * 100.0
    print(f"Category: {cat:<30} | Errors: {count:2d} ({pct_errors:4.1f}%) | Max Gain: +{max_acc_gain:.2f}%")

Implications: security, privacy, performance, scalability, and cost

DimensionCharacteristicPractical Implication
Engineering Efficiency & ROIData-centric targeting.Conducting error analysis before model development saves 60–80% of unnecessary engineering sprints by focusing on high-ceiling data bugs.
Security & Adversarial SlicesHidden low-accuracy subpopulations.Adversaries exploit unmonitored demographic or operational slices where model performance collapses to bypass fraud and authentication filters.
Inference Cost & LatencyChoosing simple baselines over GBDTs.If a Tier 2 domain rule or Tier 3 linear model matches complex ML within 0.5%, deploying the simpler baseline eliminates GPU serving costs and reduces latency to &lt; 1 ms.
Data Privacy in Error LoggingAuditing misclassified records.Manual inspection of errors requires exporting raw user records. Ensure all PII is scrubbed and data access is logged under SOC2/GDPR rules.

Alternatives: free, open source, and commercial

Tool / FrameworkArchitectureBest Used For
CleanlabConfident Learning frameworkAutomated detection of label errors and dataset annotation noise.
SnorkelProgrammatic weak supervision & slicingSlicing data and writing programmatic labeling functions.
Giskard / RagasAutomated ML & LLM test suitesAutomated slice discovery, regression testing, and hallucination checks.
Scale AI NucleusCommercial dataset debugging platformVisualizing embeddings, finding edge-case failure modes, and curating training data.

Diagnostic StrategyFocusWorkflow TypePrimary Output
Baseline HierarchyModel SelectionQuantitative BenchmarkMinimum viable performance floor
Error AnalysisFailure Root CausesQualitative / Data-CentricPrioritized Error Reduction Ceilings
Slice AnalysisSubpopulation HealthStratified Metric AuditIdentification of hidden sub-group failures
Hyperparameter TuningAlgorithm FittingAutomated Model-CentricIncremental parameter optimization

When to use it β€” and when not to

When to USE Baselines and Error Analysis:


Knowledge check

  1. 4-Tier Baseline Ladder: Dummy Majority \to Domain Rule \to Linear Model \to Complex ML.
  2. Andrew Ng Error Ceiling: Max Gain = E_cat / N_val.
  3. Data-Centric AI: Improving training data quality yields higher ROI than endless algorithmic tweaking.
  4. Slice Auditing: Uncovers catastrophic localized failures hidden behind high global accuracy averages.

Hands-on exercise

In this hands-on exercise, you will implement an automated Error Analysis engine that computes baseline comparisons, calculates slice error rates, and ranks error reduction ceilings.

import numpy as np
import pandas as pd
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score

# Step 1: Implement Baseline & Ceiling Engine
def evaluate_baselines(X_train, y_train, X_test, y_test, heuristic_pred):
    dummy = DummyClassifier(strategy="most_frequent").fit(X_train, y_train)
    linear = LogisticRegression().fit(X_train, y_train)
    
    d_acc = accuracy_score(y_test, dummy.predict(X_test))
    h_acc = accuracy_score(y_test, heuristic_pred)
    l_acc = accuracy_score(y_test, linear.predict(X_test))
    
    return {"dummy_acc": d_acc, "heuristic_acc": h_acc, "linear_acc": l_acc}

# Step 2: Test on Synthetic Verification Data
rng = np.random.default_rng(42)
X_tr = rng.normal(size=(100, 2))
y_tr = (X_tr[:, 0] > 0).astype(int)
X_te = rng.normal(size=(50, 2))
y_te = (X_te[:, 0] > 0).astype(int)

# Simple heuristic: If X[0] > 0 -> 1
h_te = (X_te[:, 0] > 0).astype(int)

res = evaluate_baselines(X_tr, y_tr, X_te, y_te, h_te)
print("=== Baseline Benchmark Results ===")
print(f"Dummy Accuracy:     {res['dummy_acc']:.4f}")
print(f"Heuristic Accuracy: {res['heuristic_acc']:.4f}")
print(f"Linear Accuracy:    {res['linear_acc']:.4f}")

Expected output

=== Baseline Benchmark Results ===
Dummy Accuracy:     0.5200
Heuristic Accuracy: 1.0000
Linear Accuracy:    1.0000

Validate your work

  1. Confirm that dummy_acc reflects majority class prevalence.
  2. Confirm that when a heuristic perfectly predicts labels, accuracy is 1.0.
  3. Test that compute_error_reduction_ceiling correctly ranks categories by maximum potential accuracy gain.

Troubleshooting

Common mistakes

  1. Skipping Simple Baselines: Launching deep models before checking whether a 2-line business rule already solves the problem.
  2. Tweaking Models Instead of Fixing Data: Spending weeks tuning hyperparameters when 50% of errors are caused by bad training labels.

Practice assignment

  1. Build a Data-Centric Relabeling Tool: Write a Python script that identifies the top 50 highest-loss training records, presents them to an annotator for re-verification, and retrains the model on cleaned data.
  2. Build an Automated Subpopulation Slicer: Write a function that fits a shallow decision tree on (X_val, I(y_val != y_val)) to automatically extract the feature combination with the highest error density.

Extension challenge

Build an Enterprise Model Error Analysis & Slicing Platform:

  1. Ingest model predictions across a 10,000-sample production validation benchmark.
  2. Compute full multi-tier baseline benchmarks (Dummy, Domain Rules, Linear, GBDT).
  3. Automatically partition errors across 5 demographic and operational metadata dimensions.
  4. Rank all error categories by Andrew Ng Error Reduction Ceilings.
  5. Export an interactive executive error audit dashboard.

Quiz

Q1. Why is establishing a simple domain heuristic baseline (e.g. basic business IF/THEN rule) mandatory before deploying a complex machine learning model?

  1. To prove that the complex model provides meaningful commercial and statistical lift over existing simple business logic, justifying its added latency, infrastructure cost, and maintenance overhead.
  2. Because scikit-learn will refuse to fit decision trees without a baseline.
  3. Because deep neural networks require domain rules to initialize backpropagation weights.
  4. To satisfy Python GIL thread concurrency constraints.
Show answer

Answer: A. To prove that the complex model provides meaningful commercial and statistical lift over existing simple business logic, justifying its added latency, infrastructure cost, and maintenance overhead.

If a 500-tree gradient booster or neural network only provides a 0.2% improvement over a 2-line domain heuristic, the added engineering complexity, inference latency, and maintenance risk are not justified.

Q2. In Andrew Ng's systematic error analysis methodology, how is the Error Reduction Ceiling for a specific error category computed?

  1. Ceiling = (Count of Errors in Category) / (Total Number of Validation Samples). It represents the maximum possible increase in global accuracy if that specific category is 100% resolved.
  2. By running grid search on learning rate across 100 epochs.
  3. By taking the logarithm of the training loss curve.
  4. By computing the determinant of the covariance matrix.
Show answer

Answer: A. Ceiling = (Count of Errors in Category) / (Total Number of Validation Samples). It represents the maximum possible increase in global accuracy if that specific category is 100% resolved.

If a model makes 100 total errors out of 1,000 validation samples, and 40 errors are caused by label noise, the maximum possible global accuracy gain from perfectly fixing labels is 40 / 1000 = +4.0%.

Q3. What is the primary danger of relying purely on an aggregated global evaluation metric (e.g. Overall 93% Accuracy) across a full test set?

  1. The high global average can completely mask catastrophic failure rates (e.g. 50% accuracy) on critical but smaller subpopulations, VIP customer cohorts, or rare edge-case operating environments.
  2. Global metrics cause floating-point underflow in GPU registers.
  3. Global metrics are not supported by scikit-learn.
  4. Aggregated scores require quadratic memory complexity.
Show answer

Answer: A. The high global average can completely mask catastrophic failure rates (e.g. 50% accuracy) on critical but smaller subpopulations, VIP customer cohorts, or rare edge-case operating environments.

Simpson's Paradox and class imbalance mean that high overall accuracy often conceals severe localized failures on critical demographic or operational slices.

Q4. What is a DummyClassifier(strategy='most_frequent') used for in production baseline benchmarking?

  1. It represents the trivial statistical floor by always predicting the single most common class in the training dataset, setting the minimum benchmark any real model must easily beat.
  2. It generates random synthetic features for data augmentation.
  3. It cleans missing values in SQL databases.
  4. It compresses tree models for mobile deployment.
Show answer

Answer: A. It represents the trivial statistical floor by always predicting the single most common class in the training dataset, setting the minimum benchmark any real model must easily beat.

In an imbalanced dataset where 95% of transactions are legitimate, a Dummy majority baseline achieves 95% accuracy by default. Any real machine learning model must achieve significant lift above this trivial floor.

Q5. What distinguishes Data-Centric AI from Model-Centric AI during error resolution?

  1. Data-Centric AI holds the model architecture fixed and systematically improves the quality, consistency, and annotations of the training data, whereas Model-Centric AI keeps dirty data fixed and repeatedly tweaks algorithms.
  2. Data-Centric AI only uses SQL databases.
  3. Model-Centric AI does not use gradient descent.
  4. Data-Centric AI is restricted to unsupervised clustering.
Show answer

Answer: A. Data-Centric AI holds the model architecture fixed and systematically improves the quality, consistency, and annotations of the training data, whereas Model-Centric AI keeps dirty data fixed and repeatedly tweaks algorithms.

Andrew Ng championed Data-Centric AI: when error analysis reveals that failures stem from mislabeled samples, missing context, or blurred images, engineering effort is focused on cleaning the data rather than endlessly tuning hyperparameters.

Glossary

Trivial Baseline
A zero-learning heuristic predictor such as majority class or mean target value.
Simple Statistical Baseline
A fast, interpretable model (logistic regression, linear regression) serving as the minimum complexity benchmark.
Human-Level Performance (HLP)
The empirical performance achieved by domain experts on a task, establishing an estimate of Bayes optimal error.
Competitive Baseline
A tuned standard algorithm (e.g. LightGBM, Random Forest) establishing the state of the art on tabular features.
Error Reduction Ceiling
The maximum possible percentage gain in overall accuracy if an error category is 100% eliminated.
Data-Centric Error Analysis
Systematically inspecting misclassified samples to categorize root causes and fix underlying data issues rather than tweaking algorithms.
Slice Performance Audit
Evaluating model performance across critical demographic, operational, or business cohorts to detect hidden failures.
Bayes Optimal Error
The lowest possible prediction error rate achievable by any classifier due to irreducible noise.

Sources and further reading


Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.