Brick Brain · teach a machine to tell cats from dogs

Scan a LEGO build with the color sensor, type in the reading, label it, and train a nearest-neighbor classifier — live, offline, on this laptop.

Start here · Your mission

This laptop knows nothing about cats or dogs. Your job is to be its teacher. You'll scan LEGO builds with a color sensor and tell the computer what each one is — then test it on a build it has never seen and watch it make its own guess.

This is exactly how real machine learning works: no rules are programmed in. The machine learns only from the examples you give it. Teach it well... or teach it badly, and see what happens. 😈

How to play: ① Scan & label 4–6 cats and 4–6 dogs below → ② Scan a mystery build and press Guess → ③ Try to fool it (hint: build a cat using the dogs' colors) → ④ When you're done, open "What just happened?" at the bottom.

Sensor: not connected Chrome: connect directly. Safari: run python sensor_bridge.py first.

1 · Train

Hold the sensor over the build and press Scan — or type readings manually / use the color picker.

this is the color you scanned
Cats: 0Dogs: 0

2 · Predict

Scan a mystery build — the model finds the 3 most similar training colors and takes a vote (k-NN, k=3).

mystery build color

3 · See what the model sees

Every scan is a point in feature space. Blue squares = cats, red squares = dogs, star = mystery build, dashed lines = its 3 nearest neighbors. Change the axes to hunt for the feature pair that best separates your cats from your dogs.

🎓 What just happened? — open this after you've played

Congratulations — you just did supervised learning, the most common form of machine learning. Here's what each part of the game was, in real ML language:

  • Scanning + labeling was "training data." Every time you pressed Label as CAT, you added a labeled example. That table of scans is the model's entire knowledge of the world — nothing more. "Supervised" just means a teacher (you!) provided the answers.
  • The guess was a "k-nearest-neighbors" prediction. The model measured how close the mystery color was to every training scan, found the 3 most similar, and took a vote. No magic — you can see the whole "brain" in the scatter plot.
  • The vote count was "confidence." A unanimous 3–0 vote means the mystery build sits deep inside one group. A 2–1 vote means it landed where cats and dogs overlap — the model is guessing, and it's telling you so. Good AI systems don't just answer; they know how sure they are.
  • The brown cat was "shortcut learning." If you fooled the model, notice why it worked: the model never learned what a cat is — it only learned which colors appeared with which label. Real AI fails the same way: a medical AI that learns the hospital's camera instead of the disease, a vision system that recognizes huskies by the snow behind them. The model learns whatever pattern separates the examples, not the concept we intended.
  • The fix is better data, not a smarter model. Add brown cats to the training set and the prediction flips. Models improve by seeing more diverse, representative examples — and this is why biased training data produces biased AI.

The one-sentence takeaway: a machine learning model is only as good as the examples it's trained on — and it will happily learn the wrong lesson from the right data.

Bonus — the other kind of learning: here you gave the machine labels. In unsupervised learning, nobody does: the machine gets a pile of unlabeled data and must find groups on its own (try sorting a pile of LEGO with no instructions — the "rules" you invent are what an algorithm like k-means does with numbers). Supervised = learning with an answer key; unsupervised = discovering structure without one.

Questions to think about: What second measurement (besides color) would make this model harder to fool? If the model is only 2/3 sure, should a robot act on it? How many training examples would be "enough" — and how would you know?

💡 Presenter notes — the teaching moments (click)
  • The shortcut trap: after training on gray cats and brown dogs, build a brown cat and scan it. The model says DOG — because it never learned "cat-ness," it learned color. Real systems fail exactly this way (classifiers that detect huskies by detecting snow).
  • More data helps: add brown cats to the training set and re-predict. Watch the decision change. This is why dataset diversity matters.
  • k-NN is inspectable: point at the plot — the prediction is literally "which labeled points is it closest to." Great contrast with black-box neural nets.
  • Sensor calibration: readings shift with lighting and distance. Recalibrate live and say "real robots fight this too."
  • Ties & confidence: if the 3 neighbors vote 2–1, that's a low-confidence call. Ask: should the robot act on it, or ask for help?