🏷️ Train a Classifier

Teach a computer to sort objects into categories by giving it training examples

πŸ“‹ Mission: Teach AI about Animals vs. Vehicles

Drag each item into a category, or tap an item and then tap a box. The computer will learn only from the way you sort them!

🐾 Animals
πŸš— Vehicles

🔬 Data Lab: What If the Training Data Is Lopsided?

This lab uses the same six facts, but the model looks at the 3 closest training examples and goes with the majority vote (a 3-nearest-neighbor model). All labels here are correct. The only thing you change is which examples it gets. Then it is tested on 12 new items in 6 groups.

Pick a training set
Or tap examples on and off:
Test groupItems and results

How the Activity Works

  1. Sort ten training items. Drag each emoji into Animals or Vehicles, or tap it and then tap a box. The game accepts whatever you choose, right or wrong, because that is how real training data works: the computer trusts its labels.
  2. Train. When all ten are sorted, press Train. The page lists what you taught it and warns you if any labels are mixed up.
  3. Test. Six new items appear: rabbit, motorcycle, shark, helicopter, turtle and scooter. Press Classify on each. The model shows its answer, which of your training items it looked most like, and whether the answer is right.
  4. Talk about bias. After the last test, a short card asks what would happen with lopsided training data.

Behind the scenes, the computer never sees a picture. Each item is a list of six facts: is it alive, does it have wheels, an engine, can it fly, does it live in water, and how many legs. The model is a 1-nearest-neighbor classifier. It measures how far apart two lists of facts are and gives each new item the label of its closest match.

Worked Example: Teaching It Wrong on Purpose

Sort everything correctly except one: put the πŸ• dog in Vehicles. Now test the rabbit. A rabbit's facts are alive, no wheels, no engine, does not fly, does not live in water, four legs. That matches the dog, cat and elephant exactly. The dog is checked first, so the model says Vehicle, most like your Dog, and marks itself wrong. The turtle, which also has four legs, makes the same mistake.

Ask the class: the model followed its rules perfectly, so whose mistake was it? This is the point of the activity. In AI4K12's words for Big Idea 3, computers can learn from data, and that training data is usually supplied by people.

Why Labels and Variety Matter in Real Life

A classifier is any system that sorts inputs into categories: spam or not spam, which song genre, which plant is in a photo. Each one learns from labeled examples, so errors and gaps in those examples become errors in its answers.

The best-known example comes from MIT's 2018 Gender Shades study. Three commercial face-analysis programs guessed gender from photos. For lighter-skinned men their error rate was never worse than 0.8%, but for darker-skinned women it rose to between 20.8% and 34.7%. A system that looks accurate overall can fail badly for groups that were under-represented when it was built and tested.

The Data Lab: Lopsided Training Data

The Data Lab below the activity keeps every label correct and changes only which examples the model sees. It uses a 3-nearest-neighbor model: it finds the three closest training examples and goes with the majority. Then it tests 12 new items in six groups (four-legged animals, water animals, flying animals, road vehicles, flying vehicles and water vehicles) and shows the overall score, the score for animals and for vehicles, and every group.

With five animals and five vehicles, every test item comes out right. With five animals and just one vehicle, the overall score is 50%, which may not sound terrible, but every single vehicle is called an animal: the one vehicle example is always outvoted by two animals. Flip it to one animal and five vehicles and every animal fails instead. The tiny set (just a dog and a car) gets everything right, because "alive" is such a strong clue in this simple model. Real data is rarely that tidy, which is why groups with few examples are where systems tend to fail, as in the Gender Shades study above.

Discussion Questions

  • If you trained with only dogs and cars, what would the model say about a fish? About a boat?
  • The scooter has wheels but no engine. Which training item is it closest to? Is "has an engine" a good fact for telling vehicles apart?
  • What fact could you add so the model never confuses a plane with an eagle?
  • Who should check an AI system's training data before it is used on people?
  • In the Data Lab, the lopsided set scores 50% overall. Why is it important to look at each group's score, not just the total?

Common Misconceptions

  • "The computer knows what an animal is." It only compares the six numbers it was given. It has no idea what "alive" means.
  • "If the answer comes from a computer, it must be right." The model is only as good as its labels. Mislabel one item and watch it repeat the error.
  • "Bias means the AI is mean." Here bias means a lopsided or incomplete set of examples that leads to unfair or wrong results for some cases.

Extension Ideas

  • Add a third category. On paper, add "plants" and decide which facts would separate a tree from an animal.
  • Human classifier. One student secretly picks a rule (for example, "things with wheels") and sorts objects. Classmates guess the rule from the examples, just as a model does.
  • Go bigger. Older students can try a tool that learns from webcam images, such as Google's Teachable Machine, and compare it with this six-fact model.

Keep going with How AI Works (a fruit classifier that shows how missing information causes mistakes) or AI vs. Human.

Framework alignment

AI4K12 Big Idea 3 (Learning) and Big Idea 5 (Societal Impact). AI4K12 publishes grade-band guidelines rather than numbered standards.

Train a Classifier: Questions and Answers

Does the classifier really learn from my sorting?

Yes. It is a real nearest-neighbor model running in your browser. For each test item it finds the training item with the most similar facts and copies the label you gave that item. Put the dog in the Vehicles box and the rabbit will come out as a vehicle.

Can my students do this on an iPad or Chromebook?

Yes. On a touch screen, tap an item to pick it up and then tap the Animals or Vehicles box. Dragging also works with a mouse.

Why does the helicopter come out as a vehicle when it has no wheels?

Its closest training example is the plane: both have an engine and fly. Only one fact (wheels) differs. The model never asks 'is it a vehicle?'; it only asks 'which example does this look most like?'

Is this how big AI systems like photo apps work?

The core idea is the same: labeled examples go in, and the system learns to label new things. Real systems use thousands to millions of examples and learn their own features from raw pixels or text, usually with neural networks, instead of six facts a person wrote down.

What should students take away?

A classifier can only be as good as its examples and labels. Wrong labels, missing kinds of examples and missing information all show up as wrong answers, and people choose all three.

Sources

Last reviewed: November 2026 Β· AI4K12 Big Ideas 3 and 5

🌟 Keep Exploring
🧠How AI Works 🎨Spot AI Art 🐾Animal Classification