Skip to content

Add the "No median feat" exercise - #17

Merged
danhalligan merged 10 commits into
mainfrom
no-median-feat
Nov 3, 2026
Merged

danhalligan merged 10 commits into
mainfrom
no-median-feat

Conversation

@danhalligan

@danhalligan danhalligan commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Adds No median feat (🌶️🌶️), a robust-estimation exercise in Uncertainty and Simulation, on simulated data so the truth is always known.

The exercise

Three stages, building from the median to a regression line that is hard to fool:

  1. Mean to median: trimmed_mean. Learners find breakdown points by glitching data, then compare bias and standard error across normal, skewed, heavy-tailed and glitched samples.
  2. A robust spread: mad and flag_outliers, showing why the 3σ rule cannot flag anything in a sample of ten.
  3. A line that shrugs: theil_sen, compared with least squares under clean, glitched and skewed noise, and where its breakdown point really is.

The learner functions are unfinished stubs, as in other exercises. Their 13 tests fail until implemented.

Supplied helpers

exercises/no_median_feat/simulation.py provides glitch, sample and simulate, so the notebook is not full of Monte Carlo boilerplate. They share one set of noise options (normal, exponential, t, all with the same mean and standard deviation) and accept a seeded rng. They have their own tests in tests/test_no_median_feat_simulation.py, which pass.

Also changed

  • Catalogue entry in the root README.md and a NEWS.md line.
  • no_median_feat added to REQUIRED_NOTEBOOKS in tests/test_notebooks.py.

Checks

ruff check, ruff format --check, pytest --collect-only and pytest tests -q all pass.

Merge order

The reference solution is in the private solutions repo. That PR verifies against this repo's main, so merge this one first and then re-run it.

danhalligan and others added 10 commits November 2, 2026 15:10
Starter code, tests and notebook for trimmed means, MAD, outlier flagging
and Theil-Sen regression, with simulation to measure breakdown and
efficiency.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the notebook's contaminate function with glitch, which chooses the
glitch size, direction and position and accepts a seeded generator.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Theil-Sen is more precise than least squares under skewed noise, and the 29%
breakdown point is a worst case: random glitches do far less harm.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
simulate yields noisy straight-line datasets with normal or skewed noise and
optional glitches, so the notebook's Monte Carlo loops need no boilerplate.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
sample yields one-dimensional samples (normal, exponential or t, with optional
glitches) so section 2 can compare estimators across kinds of data. simulate
shares the noise options.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…d exercises

The module now holds glitch, sample and simulate. A likely story, Known unknowns
and the root README point to the new exercise.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the skewed-noise intercept question into section 4, where the data already
are, and compare only glitches at the start with glitches at random positions.
The other glitch options become an extension.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danhalligan
danhalligan merged commit 43d5cff into main Nov 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant