Applications of Machine Learning

Lecture 1 · Animations

What machine learning is, and how we will work

The first look at a dataset is a histogram of every column, and the most consequential fact in this one — a target that stops dead at a ceiling — is visible or invisible depending on a single argument. The widget below builds a histogram of a capped price one batch of districts at a time. Press Step to add a batch and read what happened.

All data on this page is synthetic, generated in your browser from a fixed seed, so Reset always gives back the same picture.

1A cap, and the bins that hide it

20,640 synthetic districts, each with a median house value drawn from a smooth, right-skewed distribution — and then, as in the census data, every value above 500,000 dollars recorded as 500,001. Each Step adds 516 districts to the histogram. The slider sets the number of bins; the last bar, which holds the cap, is drawn in the accent colour.

The mathematics

With $m$ districts and $b$ equal bins of width $w$ over the range, a bar over a stretch where the values have a smooth density $f$ holds about $m\,f(x)\,w$ districts — it shrinks in proportion to $w$. The capped districts, a share $p$ of all of them, sit at one value, so they land in one bar whatever $w$ is:

$$\frac{\text{cap bar}}{\text{its neighbour}} \;\approx\; \frac{p + f\,w}{f\,w} \;=\; 1 + \frac{p}{f\,w}.$$

Since $w$ is the range divided by $b$, the ratio grows roughly linearly in the number of bins. Too few, and the cap is one bar among its neighbours.

Watch for
  • At 50 bins the last bar stands many times taller than the one beside it; at 10 bins it is only about twice as tall, and reads as the tail of a skewed distribution.
  • The share of capped districts does not depend on the bins at all: it is a count, and the readout gives it whatever the slider says.
  • The ratio is noisy for the first few batches and settles as the districts accumulate.
Try this
  1. Run to the end at 50 bins, then drag the slider down to 10. The same data, and the spike all but disappears.
  2. Drag it up to 100: the ratio roughly doubles again, as $1 + p/(f\,w)$ predicts when $w$ halves.