Teaching with the labs
Each lab is designed for a single misconception and a single class of decisions. The pattern below takes about fifteen minutes and works as a lecture interlude, a lab section, or an asynchronous assignment. Every lab also ships named learning activities — listed underneath each entry below and inside the lab's Activities tab — with a time budget, an audience, and something the student hands in.
1. Predict
Students answer the prediction prompt before touching a control. Most classes converge on the same wrong answer, which is exactly the point — the disagreement is the lesson.
2. Observe
Load a preset and move one control. The linked graphics update immediately, so cause and effect stay attached. Teacher mode surfaces the readouts worth writing on the board.
3. Explain
Open the mathematics tab to name what was seen, then the R bridge to connect it back to the textbook's code. Students export a permalink with their notes.
Misconception inventory
The claim each live lab is built to overturn, with the correction it demonstrates.
Sampling Distributions & the Limits of the CLT
Chapter 1 — Foundations, Data Science, Ethics, and the R Environment
“Once n is above about 30, the sampling distribution is normal.”
The threshold is a rule of thumb for mildly skewed, finite-variance populations. Log-normal data at n = 30 is still visibly skewed, and Cauchy data is never normal at any n because the CLT's finite-variance hypothesis fails.
Missingness Mechanisms: MCAR, MAR, MNAR
Chapter 2 — Data Quality, Missingness, and Exploratory Visual Analytics
“If I impute the missing values, I have recovered the missing data.”
Imputation is a device for using the rows you kept, not for recreating information you never observed. Mean imputation fabricates a spike at the centre and shrinks the variance; under MNAR, even a perfectly specified conditional model remains biased because the deletion depends on the value that was deleted.
Conditioning, Collinearity, and Unstable Coefficients
Chapter 3 — Linear Algebra, Matrix Computing, and Regression
“Collinearity biases my regression coefficients, so I should drop one predictor.”
Least squares stays unbiased at any ρ < 1; only the variance inflates. Dropping a genuinely relevant predictor introduces real omitted-variable bias, trading a variance problem for a bias problem. If prediction is the goal, collinearity may be harmless; if a single coefficient must be interpreted, the fix is better data or a regularized/identifiable target such as the sum.
PCA Geometry: Projection, Scale, and What Variance Means
Chapter 4 — Linear and Nonlinear Dimensionality Reduction
“PCA finds the intrinsic structure of my data, whatever units I measure in.”
PCA on the covariance matrix is not invariant to rescaling a single variable. Changing metres to millimetres inflates that variable's variance by a factor of a million and drags PC1 onto it. Only decomposition of the correlation matrix (standardizing first) is invariant, which is why it is the default for variables in different units.
Accuracy Is a Trap: Metrics Under Class Imbalance
Chapter 5 — Supervised Classification
“My classifier is 99% accurate, so it works well.”
With 1% prevalence, predicting “negative” for everyone is 99% accurate and useless. Accuracy weights both error types by their frequency, which hides failures on the rare class that usually matters most. Report sensitivity and precision at a stated threshold, plus AUC or average precision for the ranking, and always give the majority-class baseline for comparison.
Cluster Geometry: k-means, DBSCAN, and Shapes That Break Them
Chapter 8 — Unsupervised Clustering
“The elbow in the inertia curve tells me the right number of clusters.”
Inertia falls monotonically with k by construction, and on data with no clusters at all it still produces a smooth curve with a visible bend. An elbow is a heuristic about diminishing returns, not evidence about the number of groups. Use it alongside stability across resamples, a validation index appropriate to the cluster shape, and — decisively — subject-matter meaning.
Calibration Is Not Discrimination
Chapter 9 — Model Performance Assessment and Validation
“My model has an AUC of 0.85, so its predicted probabilities are reliable.”
AUC only measures whether positives are ranked above negatives; it is invariant to every monotone rescaling of the scores. A model can achieve any AUC while reporting probabilities that are systematically double the truth. Whenever probabilities feed a decision — treatment thresholds, expected loss, resource allocation — you must report calibration (reliability diagram, ECE, Brier, log loss) alongside discrimination, and recalibrate if needed.
LASSO Paths, Cross-Validation, and False Discoveries
Chapter 11 — Variable Importance and Controlled Feature Selection
“The variables selected at the cross-validated λ are the true predictors.”
Cross-validation optimizes out-of-sample prediction error, and prediction tolerates extra weakly correlated variables far more happily than it tolerates dropping a real one. So the CV-optimal model habitually includes false discoveries, and it also under-reports the size of true effects because of shrinkage. For inferential claims about which variables matter, use methods designed for that target — knockoffs, stability selection, or debiased inference — rather than reading off the LASSO's support.
Breakdown Points: Which Summaries Survive Contamination
Chapter 2 — Data Quality, Missingness, and Exploratory Visual Analytics
“If I have plenty of data, a few strange values cannot really matter.”
Sample size does not protect a non-robust estimator. The mean is a linear functional of the data, so one observation at distance d shifts it by d/n — and an adversarial or instrument-error value can have unbounded d. Robustness is a property of the estimator, not of the sample size. Conversely, trimming is not free: a 10% trimmed mean breaks down at exactly 10% contamination.
- Breakdown audit — 12 min · student. Measure the breakdown point of four estimators empirically and match the numbers to theory.
- Design a detector — 15 min · student. Turn SD/MAD into a decision rule and find where it fails.
- Board demonstration — 8 min · instructor-led. Open a class with a falsified intuition before any formula appears.
Testing Many Things at Once
Chapter 2 — Data Quality, Missingness, and Exploratory Visual Analytics
“Each of my tests uses α = 0.05, so I have a 5% chance of a false conclusion.”
α = 0.05 is a per-test guarantee. Across m₀ independent nulls, the probability of at least one false positive is 1 − 0.95^m₀ — 40% at m₀ = 10 and above 99% at m₀ = 100. Only a multiplicity procedure restores a study-level guarantee, and you must choose which guarantee you want: FWER (no false positives at all) or FDR (a bounded fraction of your reported discoveries).
- Manufacture a false discovery — 10 min · student. Experience the multiplicity problem before naming it.
- Bonferroni versus BH under a power budget — 18 min · student. Quantify the power price of each guarantee and defend a choice.
- Forking-paths debrief — 12 min · whole class. Connect the simulation to how analyses actually go wrong.
Regression Is a Projection
Chapter 3 — Linear Algebra, Matrix Computing, and Regression
“The regression line and the first principal component are two names for the line of best fit.”
They minimize different distances. OLS minimizes the squared vertical gaps, so it depends on which variable you call the response — swapping x and y gives a different line. PC1 minimizes perpendicular gaps and is symmetric in the two variables. The gap between them grows with the noise-to-signal ratio, and with large noise OLS visibly under-estimates the slope while PC1 does not.
- Verify the normal equations numerically — 10 min · student. Connect the algebraic identity Xᵗe = 0 to a number on screen.
- Which line, and who decides? — 15 min · student. Show that the choice of loss, not the data, determines the fitted line.
- Influence forensics — 12 min · whole class. Distinguish outlier, leverage, and influence with one movable point.
- Projection lecture opener — 6 min · instructor-led. Introduce the hat matrix as geometry rather than algebra.
k-NN Boundaries, Bias–Variance, and the Bayes Floor
Chapter 5 — Supervised Classification
“My classifier got every training case right, so it will do well on new patients.”
A 1-nearest-neighbour rule achieves zero training error on any dataset, including randomly labelled noise, because each training point is its own nearest neighbour. Training error measures memorization capacity, not generalization. Only an estimate that never uses a case in its own prediction — leave-one-out, k-fold, or a held-out test set — measures the quantity you care about, and even that estimate is bounded below by the Bayes error implied by class overlap.
- Find the sweet spot — 15 min · student. Locate the bias–variance optimum empirically and describe both failure modes.
- Break the smoothness assumption — 12 min · student. Show that “simpler is safer” is false when the structure is local.
- Meet the floor — 12 min · student. Separate reducible from irreducible error.
- Validation demonstration — 8 min · instructor-led. Motivate cross-validation in one screen before defining it.
TF-IDF Geometry: Angle, Length, and What Similar Means
Chapter 7 — Text Mining, NLP, and Association Rule Learning
“Documents are points in space, so Euclidean distance tells me which are alike.”
With bag-of-words counts, vector length encodes document length rather than content. A 60-token clinical note and a 20-token clinical note differ mostly in norm, so Euclidean distance ranks them far apart while cosine — which only reads the angle — ranks them together. Text retrieval therefore compares directions, using L2 normalization or cosine, and re-weights terms by IDF so that words appearing everywhere stop dominating the direction.
- Length versus topic — 12 min · student. Show that Euclidean distance on counts measures length, not subject matter.
- Earn the IDF — 15 min · student. Quantify what IDF buys over plain stop-word removal.
- Classify the ambiguous document — 10 min · whole class. Use nearest-neighbour retrieval on cosine to expose the effect of representation choices.
- Vectorizing walkthrough — 8 min · instructor-led. Derive TF-IDF at the board with numbers the class can verify on screen.
Holdout, k-Fold, LOO, Bootstrap: Estimating an Estimator
Chapter 9 — Model Performance Assessment and Validation
“I split the data 70/30, so the number I got is the model's accuracy.”
A single split gives one draw from a sampling distribution that can be very wide when n is small. In this lab, at n = 40 the holdout estimate routinely lands 30–50% above or below the true prediction error, so two competent analysts with identical data and identical models report different accuracies. k-fold averages over k splits and materially reduces that variability, and the estimate should always be reported with its uncertainty rather than as a point value.
- Two honest reports — 12 min · student. Feel the variance of a single holdout split.
- Scheme bake-off — 20 min · student. Choose a scheme on total error rather than bias alone.
- Optimism of the training error — 12 min · student. Show that apparent error is a function of complexity, not of quality.
- Reproducibility seminar — 15 min · instructor-led. Link validation variance to the replication crisis.
Gradient Descent: Step Size, Conditioning, and Momentum
Chapter 13 — Optimization and Numerical Methods
“My loss exploded, so the loss surface must have a bad region or a saddle.”
Divergence on this lab's objective happens on a strictly convex quadratic with a unique minimum, purely because η exceeded 2/L. Step size interacts with the largest curvature, and no property of the landscape is needed to explain the failure. Symmetrically, slow progress on an ill-conditioned bowl looks like a plateau but is just the (κ−1)/(κ+1) rate — the fixes are scaling, preconditioning, and momentum, not a different loss function.
- Find the stability edge — 12 min · student. Verify the 2/L bound experimentally.
- What momentum buys — 15 min · student. Measure a convergence rate from a log-loss slope.
- Conditioning is a modelling choice — 12 min · whole class. Connect κ to feature scaling in a real pipeline.
- Optimizer clinic — 10 min · instructor-led. Give students a diagnostic procedure for a training run that will not converge.
Autocorrelation, Stationarity, and Effective Sample Size
Chapter 12 — Time Series, Longitudinal, and Survival Analysis
“I have 200 measurements, so my standard error is s/√200.”
That formula assumes independence. With AR(1) dependence the variance of the mean is inflated by (1 + φ)/(1 − φ): at φ = 0.85 the 200 observations carry the information of about 16 independent ones, and the honest standard error is roughly 3.5 times the naive one. Confidence intervals and p-values computed as if time-ordered data were a random sample are systematically overconfident — this is one of the most common errors in applied longitudinal work.
- How much data do you really have? — 15 min · student. Quantify the information cost of serial dependence.
- Identify the process — 15 min · student. Learn the ACF/PACF signature that drives model identification.
- Unit root and the differencing cure — 12 min · student. Distinguish a stationary persistent process from a random walk.
- Longitudinal-inference audit — 15 min · instructor-led. Make students re-examine an earlier result under dependence.
Floating Point Has Edges
Chapter 1 — Foundations, Data Science, Ethics, and the R Environment
“These formulas are algebraically identical, so it does not matter which one I code.”
Algebra says nothing about rounding. The one-pass formula subtracts two large nearly equal quantities, so its relative error grows like ε·(μ/σ)² and it can return a negative variance. The centred and Welford forms compute the same quantity with error near machine epsilon regardless of location. Choosing the numerically stable form is part of the statistics, not an implementation detail.
- Find the breaking point — 12 min · student. Locate empirically where a standard formula stops working, and explain it with ε·(μ/σ)².
- Refactor an unstable routine — 18 min · student. Turn the diagnosis into working, tested code.
- Reproducibility debrief — 10 min · whole class. Connect rounding to reproducibility claims made elsewhere in the course.
Matrices as Motions
Chapter 3 — Linear Algebra, Matrix Computing, and Regression
“As long as the determinant is not zero, the matrix is safe to invert.”
The determinant is a product, so it can stay comfortably away from zero while one singular value is tiny — scale a matrix up and det grows by the square. What controls stability is the ratio σ₁/σ₂: an almost-collapsed ellipse means almost-collinear columns, and solving with such a matrix amplifies noise by κ regardless of what det reports.
- Build four named motions — 15 min · student. Connect matrix entries to geometric behaviour by construction rather than by recognition.
- Engineer a near-collapse — 15 min · student. See rank deficiency as geometry and link it to regression instability.
- Eigen versus singular, whole class — 12 min · whole class. Establish why the SVD, not the eigendecomposition, is the general tool.
The Irreducible Floor
Chapter 5 — Supervised Classification
“If my accuracy is stuck at 82%, I need a stronger model.”
First compute the floor. If the classes overlap enough that the Bayes error is 18%, then 82% is optimal and every hour spent on a bigger model is wasted; the gain must come from better features that separate the densities. Conversely, an accuracy below the majority-class baseline means the model is worse than a constant. Always locate your result between the baseline and the ceiling before interpreting it.
- Estimate the ceiling before modelling — 15 min · student. Make the irreducible floor the first quantity computed in any classification task.
- Manufacture optimism — 15 min · student. Experience selection-induced optimism as a mechanism, not a warning.
- Prior shifts and the cost of a rare class — 12 min · whole class. Separate the likelihood from the base rate in a decision rule.
Support, Confidence, and Lift
Chapter 7 — Text Mining, NLP, and Association Rule Learning
“This rule has 92% confidence, so buying A strongly predicts buying B.”
Compare it with P(B). If B is in 90% of baskets, a 92% confidence rule is barely distinguishable from independence and its lift is 1.02 — the rule tells you almost nothing you did not know from B's marginal frequency. High confidence is necessary but not sufficient; report lift or leverage alongside it, and remember all three are symmetric associations rather than causal claims.
- Two rankings, two recommendations — 15 min · student. Show that the choice of interest measure changes the business decision.
- Recover the planted signal — 18 min · student. Practise separating one real dependence from many spurious high-confidence rules.
- Threshold policy for a real catalogue — 12 min · whole class. Decide support and confidence thresholds deliberately rather than by default.
Net Benefit and Threshold Choice
Chapter 9 — Model Performance Assessment and Validation
“The model has AUC 0.85, so it is ready to guide treatment decisions.”
AUC is a threshold-free ranking measure: it says nothing about whether acting on the model at any particular cutoff beats treating everyone or nobody. Under low prevalence a well-ranked model can still sit below the treat-all line for every threshold a clinician would accept. Decision curve analysis makes usefulness explicit, and it demands one thing AUC does not: that you say what a false positive costs relative to a false negative.
- Set your own exchange rate — 15 min · student. Derive a threshold from a defensible statement about consequences.
- AUC versus usefulness — 18 min · student. Demonstrate that discrimination and clinical value are different questions.
- Committee decision — 15 min · whole class. Practise defending a threshold to stakeholders with different loss functions.
Amdahl's Ceiling
Chapter 10 — Big Data, Formats, and Computational Performance
“Our pipeline takes six hours on one machine, so on sixty machines it will take six minutes.”
Only if every step parallelises perfectly and coordination is free. Profile first: if 8% of the runtime is serial — reading configuration, writing a single output file, a final sort — the ceiling is 12.5×, so six hours becomes about 29 minutes at best, and any communication cost makes it worse. The honest engineering question is not how many workers to add but which serial fraction to remove.
- Profile before you provision — 15 min · student. Turn a measured serial fraction into a defensible hardware decision.
- The cluster that got slower — 12 min · student. Diagnose a super-linear cost curve from its shape.
- Strong versus weak scaling debate — 12 min · whole class. Give students language for reporting scaling results honestly.
Censoring and the Kaplan–Meier Estimator
Chapter 12 — Time Series, Longitudinal, and Survival Analysis
“Forty patients were lost to follow-up, so we removed them from the survival analysis.”
Those forty were event-free for as long as they were observed, and that is real information about the survival curve up to their last visit. Removing them biases the estimate upward (the remaining sample is enriched for people observed long enough to have events) while counting them as events biases it sharply downward. Kaplan–Meier keeps them in the risk set until their censoring time and drops them afterwards, which is why it is the standard estimator — provided censoring is independent of prognosis.
- Quantify the censoring bias — 18 min · student. Measure how wrong the censoring-as-event analysis becomes as dropout rises.
- Tail instability and the risk table — 15 min · student. Show why late-curve differences are rarely evidence.
- Design the trial — 20 min · whole class. Trade sample size against follow-up length for a fixed effect.
What a Convolution Actually Computes
Chapter 14 — Deep Learning and Representation Learning
“Convolutional layers work by smoothing the image, so they should always help.”
Smoothing is one kernel among infinitely many, and it is the one a network rarely learns. A convolution is a local template match whose nine weights are learned; zero-sum kernels ignore brightness entirely and respond only to change. The layer helps only when its built-in assumptions hold — that nearby inputs are related and absolute position does not matter. On tabular features, where column order is arbitrary, those assumptions are false and a dense layer is the right choice.
- Build a detector by hand — 18 min · student. Connect kernel weights to the feature they select.
- Shape arithmetic without guessing — 12 min · student. Predict output shapes from padding, stride, and pooling.
- The parameter-count argument — 15 min · whole class. Justify weight sharing as regularisation, and know when it fails.
Seeds, Streams, and Reproducibility
Chapter 1 — Foundations, Data Science, Ethics, and the R Environment
“Randomness means a computation can't be reproduced, and any seed is as good as any other.”
A pseudo-random generator is deterministic given its seed: the same seed always produces the same stream, so recording the seed makes a 'random' study exactly repeatable. But not all seeds are interchangeable in practice — seeding parallel workers naively by index (1, 2, 3, ...) can start highly correlated streams, which breaks the independence a parallel simulation relies on even though every individual worker is running the identical deterministic algorithm.
- Reproduce a classmate's number — 8 min · student. Feel the difference between a seed you can hand off and a clock-seeded run you cannot.
- Break a parallel study — 10 min · student. Diagnose the naive-seeding collision hazard in parallel simulation.
- Seed policy debrief — 10 min · whole class. Turn the simulation into a reproducibility checklist for real analyses.
SVD as an Optimal Summary
Chapter 4 — Linear and Nonlinear Dimensionality Reduction
“Increasing the number of retained components always makes the summary better.”
It always makes the training reconstruction error weakly better, since each extra term can only add energy — but past the point where the retained components represent the true signal, the extra components are reconstructing noise. That is expensive (more storage per component) and does not generalize: it fits idiosyncrasies of this particular noisy draw, not the underlying pattern.
- Find the elbow — 8 min · student. Identify the effective rank of a noisy signal from its singular value spectrum.
- Compression trade-off — 6 min · whole class. Connect compression ratio to reconstruction quality using the storage formula.
- Teach the bound — 10 min · instructor-led. Use the lab to derive the Eckart–Young error formula live with students.
Where Leakage Hides
Chapter 5 — Supervised Classification
“As long as I evaluate on a held-out test set — or use k-fold cross-validation — my accuracy number is trustworthy.”
A held-out set only protects you if nothing about it influenced the model before that final evaluation. Feature selection, scaling, or imputation fit on the full dataset, or a split that fails to respect subjects or time, all let the test set quietly inform training. The reported number is then measuring memorization, not generalization.
- Find the leak by elimination — 12 min · student. Practice diagnosing which pipeline step caused an inflated score.
- Design a pipeline that cannot lie — 15 min · whole class. Translate the toggles into a written analysis plan.
- The p-vs-accuracy curve as evidence — 8 min · instructor-led. Use the sweep chart to make selection bias visible without algebra.
Clustering Through the Graph Laplacian
Chapter 8 — Unsupervised Clustering
“Clustering means finding groups that are round blobs in space, so k-means is 'the' clustering algorithm.”
k-means partitions space by Euclidean distance to centroids, which only recovers convex, roughly spherical groups. Spectral clustering instead asks which points are locally connected on a similarity graph, so it recovers clusters defined by connectivity and shape — moons, rings, spirals — that are not separable by any set of centroids.
- Break k-means on purpose — 10 min · student. See a concrete geometric failure mode of centroid-based clustering.
- Tune the bandwidth by eigengap — 15 min · student. Connect a hyperparameter choice to a spectral diagnostic.
- Full graph vs kNN graph — 12 min · whole class. Understand why sparsifying the affinity graph can help.
Importance Depends on the Question
Chapter 11 — Variable Importance and Controlled Feature Selection
“The variable with the highest importance score is the one that causes the outcome.”
Every measure here is a statistical summary of association or predictive loss under a specific procedure, not an estimate of a causal effect. Correlated duplicates, refit-vs-fixed-model differences, and even the number of categories in a variable all move these scores without touching the underlying data-generating process. Ask 'important for what question, computed how' before comparing rankings across variables or across methods.
- Watch credit split between twins — 12 min · student. See that correlated variables do not lose their combined signal, they redistribute it differently across methods.
- Build the high-cardinality trap — 15 min · student. Reproduce, quantitatively, why raw impurity reduction favors high-cardinality splitters even absent signal.
- Choose a measure for a claim — 10 min · whole class. Connect the lab to a real reporting decision.
One Pass, Bounded Memory
Chapter 10 — Big Data, Formats, and Computational Performance
“If you have the memory for exact statistics, computing them exactly is always the right choice.”
Exact statistics require O(n) memory to support order statistics like the median, and a naive one-pass variance formula is numerically unsafe once values are large or shifted. Streaming estimators are not merely a fallback for scale: Welford's update is strictly more accurate than the naive formula at any n, and sketches expose an explicit, tunable memory-for-accuracy trade that exact recomputation hides until it runs out of RAM.
- Break the naive variance formula — 10 min · student. See catastrophic cancellation happen, not just read about it.
- Tune a count-min sketch — 15 min · student. Connect hash-table width and depth to the size of the overestimation error.
- Draw the memory-accuracy frontier — 15 min · whole class. Make the sketch trade-off quantitative rather than qualitative.
Backtesting Without Peeking
Chapter 12 — Time Series, Longitudinal, and Survival Analysis
“Cross-validation is cross-validation — a random k-fold split gives the same honest error estimate for a time series as it does for i.i.d. data.”
Random k-fold assumes exchangeability: any observation could equally well be used to predict any other. Time series break that assumption by construction — the future depends on the past, not vice versa. Letting a fold's training set include points after the target time leaks information a real forecaster would never have, and the reported error is optimistic, sometimes dramatically so. Rolling-origin or expanding-window evaluation, which only ever trains on the past, is the honest analogue of cross-validation for sequential data.
- Catch the leak — 12 min · student. See the size of the k-fold optimism directly, on one model.
- Find the crossing horizon — 15 min · student. Connect MASE = 1 to the practical limit of forecastability.
- Design a fair backtest — 15 min · whole class. Translate the simulator's lesson into a checklist for real forecasting projects.
Backpropagation, One Edge at a Time
Chapter 14 — Deep Learning and Representation Learning
“Backpropagation is the algorithm that trains a neural network.”
Backpropagation only computes ∂L/∂w for every weight, using the chain rule layer by layer. Training also requires an update rule — plain gradient descent, momentum, Adam, or anything else — that decides how to use those derivatives. The gradients in this lab do not change if you imagine using a different optimizer; only the weight-update arithmetic would.
- Hand-verify one backward pass — 12 min · student. Connect the chain-rule formulas to the numbers on the graph.
- Vanishing gradients, measured — 15 min · student. Turn 'sigmoid networks are hard to train deep' into a number.
- Backprop versus gradient descent, debated — 10 min · whole class. Separate the derivative computation from the optimizer decision explicitly.
Fairness Criteria Cannot All Hold
Chapter 1 — Foundations, Data Science, Ethics, and the R Environment
“A fair model satisfies every fairness definition at once.”
Demographic parity, equal opportunity, and calibration are each defensible on their own, but they are mathematically incompatible whenever the two groups have different base rates and the classifier is imperfect. Picking a 'fair' model means choosing which criterion to prioritize, not finding a model that satisfies all of them — this is a provable impossibility result, not a modeling failure.
- Break demographic parity by hand — 12 min · student. Feel the trade-off before naming it.
- Quantify the impossibility result — 18 min · student. Connect the forced-parity panel to the algebraic identity linking PPV, TPR, FPR, and base rate.
- Policy debrief — 15 min · whole class. Turn the numbers into a decision-making conversation.
Nonlinear Embeddings Invent Structure
Chapter 4 — Linear and Nonlinear Dimensionality Reduction
“If a t-SNE plot shows separated blobs, the data has that many real clusters, and the distance between blobs tells you how different those clusters are.”
t-SNE's objective only tries to preserve small pairwise probabilities — who is a near neighbour of whom — while an aggressive early-exaggeration phase and a heavy-tailed embedding kernel actively encourage tight, well-separated visual clumps regardless of whether such structure exists upstream. Global quantities like the number of blobs, their sizes, and the distances between them are not optimized at all and can change completely with the random seed, the perplexity, or the learning rate on identical data. PCA, which has no such mechanism, shows the same noise or single-blob data as one undifferentiated cloud.
- Manufacture clusters from nothing — 12 min · student. Directly witness t-SNE inventing structure that is provably absent.
- Perplexity sweep on real versus fake structure — 18 min · student. See how the same knob behaves very differently depending on whether clusters are real.
- PCA as a sanity check — 10 min · whole class. Use a linear method with no crowding mechanism as a control condition.
The Kernel Trick, Drawn
Chapter 6 — Black-Box Methods: Neural Networks, SVM, and Ensembles
“A kernel like RBF works by first computing the coordinates of each point in a high-dimensional feature space.”
It never does. The dual SVM only needs inner products K(xᵢ,xⱼ), and the kernel function computes that scalar directly from the two low-dimensional inputs — for RBF, exp(−γ‖x−y‖²) is one exponential of one distance, not a dot product taken after mapping to an infinite-dimensional space. The 'explicit feature dimension' readout in this lab shows what you would need to compute by hand if you insisted on doing it the slow way; the kernel-matrix cost readout shows what the SVM actually pays, and it never depends on that dimension.
- Boundary shapes from kernel choice — 12 min · student. Connect the algebraic form of a kernel to the geometric shape of boundary it can draw.
- Watch the lift happen — 15 min · student. Build intuition for what a feature map actually does to data.
- The trick, quantified — 15 min · whole class. Make the computational argument for kernels concrete with numbers, not just intuition.
EM, Step by Step
Chapter 8 — Unsupervised Clustering
“EM finds the maximum likelihood solution — its guaranteed convergence means it finds the best fit.”
EM guarantees that the log-likelihood never decreases from one iteration to the next, and that the sequence converges to a stationary point. It does not guarantee that this stationary point is the global maximum. With bad initial parameters, EM converges to a local optimum with a strictly lower log-likelihood than another run from a better start on the identical data — exactly what the compare-seeds panel and the worst-case-corner initialization demonstrate.
- Catch EM at a bad local optimum — 12 min · student. See directly that convergence and optimality are different claims.
- E-step vs. M-step, one click at a time — 15 min · whole class. Build a mechanical intuition for what each half of an EM iteration actually changes.
- Seeds and the illusion of determinism — 15 min · student. Quantify how often EM's answer changes with the initialization, on fixed data.
Overparameterized and Still Improving
Chapter 14 — Deep Learning and Representation Learning
“Test error is U-shaped in model capacity: more parameters than data always means overfitting and gets worse forever.”
Test error is worst exactly at the interpolation threshold p = n, not beyond it. Once the model has enough capacity to interpolate the training data in many different ways, the minimum-norm (or otherwise regularized) choice among those solutions gets smoother — not wilder — as capacity keeps growing, producing a second descent in test risk.
- Find the spike — 10 min · student. See the interpolation threshold as a property of p/n, not of noise or feature type.
- Ridge tames the peak — 15 min · student. Connect implicit and explicit regularization by watching the peak flatten under ridge.
- Predict, then look at the fit — 12 min · whole class. Use the fitted-function panel to make double descent concrete rather than abstract.
The Same Data, Six Charts
Chapter 2 — Data Quality, Missingness, and Exploratory Visual Analytics
“A chart is a neutral window onto the data — it just shows what's there.”
Every chart embeds choices that a viewer cannot see from the picture alone: bin width, axis limits, aspect ratio, linear-vs-log scale, level of aggregation, and colour mapping. None of those choices touch the underlying numbers, but all of them change the story a viewer walks away with. Reading a chart honestly means asking what was chosen before asking what it shows.
- Two claims, one dataset — 15 min · student. Produce two charts from identical data that support opposite claims.
- Bars hide the overlap — 12 min · student. See what a bar-of-means chart discards.
- Anscombe without the picture — 10 min · whole class. Show why summary statistics are not sufficient description.
Bagging, Boosting, and Variance
Chapter 6 — Black-Box Methods: Neural Networks, SVM, and Ensembles
“Bagging and boosting are basically the same idea — averaging trees — so it doesn't matter which one you pick, and more trees eventually overfits any forest.”
Bagging averages independent trees fit to resampled data; it reduces variance at roughly fixed bias and its test error plateaus as trees accumulate, because independently-fit trees eventually stop adding new information. Boosting fits trees sequentially to residuals with a learning rate; it reduces bias fast, but with a high learning rate and enough rounds it starts fitting training noise, and test error can rise again. The two curves in the error panel above have visibly different shapes for exactly this reason.
- Find the plateau — 12 min · student. Show that a random forest's test error does not keep rising with more trees.
- Break boosting on purpose — 15 min · student. Produce a boosting overfitting curve and diagnose the fix.
- Bias versus variance, side by side — 15 min · whole class. Connect the decomposition panel to the general bias/variance tradeoff from earlier chapters.
Controlled Selection with Knockoffs
Chapter 11 — Variable Importance and Controlled Feature Selection
“If I rank features by importance (or fit a model and read off p-values), the top-ranked ones are the discoveries I can trust.”
A ranking, by construction, always returns an answer — the top k features exist whether or not any of them are real, and an uncorrected p-value threshold ignores how many tests were run. Neither carries a false discovery rate guarantee. The knockoff filter instead builds a synthetic negative control for every feature and uses the sign pattern of real-vs-decoy competition to certify, before you ever see the data twice, that the expected fraction of false discoveries stays below q.
- Break the ranking rule — 12 min · student. See that a plausible-looking selection rule can have an arbitrarily bad false discovery rate.
- Exchangeability by eye — 10 min · student. Connect the abstract exchangeability condition to a concrete correlation heatmap.
- Knockoff vs knockoff+ near the edge — 15 min · whole class. Feel the practical difference between the two thresholds when few discoveries are made.
Constraints Bind
Chapter 13 — Optimization and Numerical Methods
“The constrained optimum is just the unconstrained minimum, clipped into the feasible region.”
Clipping projects a single point — the unconstrained minimum — onto the boundary using only the direction from the center of the constraint, ignoring the objective's gradient entirely at the projection step. The true constrained optimum is where the objective's gradient is anti-parallel to the constraint's gradient, which is generally a different point on the boundary. The gap readout in this lab makes that difference numeric, not just visual.
- Read λ two ways — 12 min · student. Connect the multiplier readout to the sensitivity curve's slope.
- Falsify the clipping shortcut — 15 min · student. Produce a case where clipping fails badly.
- KKT at the boundary of activity — 10 min · whole class. See complementary slackness flip.
Where to Sample Next
Chapter 13 — Optimization and Numerical Methods
“Grid search and Bayesian optimization differ only in speed.”
They differ in what each query depends on. Grid search fixes every location in advance regardless of the data; Bayesian optimization recomputes a posterior after each observation and lets the acquisition function choose the next location adaptively. The efficiency panel shows BO reaching a given best-value threshold in far fewer evaluations on average — not because it evaluates faster, but because it evaluates smarter. And the same adaptivity that helps it can hurt it: an over-smooth surrogate or an overly exploitative acquisition can make BO commit early and get stuck, something grid search's blind uniform coverage never does.
- Break the surrogate, then fix it — 10 min · student. Connect the length-scale hyperparameter to what the acquisition function can and cannot see.
- Race three search strategies — 8 min · whole class. Use the sample-efficiency panel to falsify the 'only speed differs' misconception with numbers.
- Design an initial batch — 7 min · instructor-led. Discuss the role of the initial design size before any adaptive sampling occurs.
