AP Computer Science Principles Β· Machine Learning
The Fruit Farmer Activity
Teaching a computer to grade produce: supervised learning, training data, and classification. Students grade tomatoes by hand, train an AI on their labels, and then watch it grade tomatoes it has never seen.
- About 45 minutes
- Students, solo or in pairs
- No coding
- No login required
Part 1: Before You Play
In this activity you become a quality inspector at a produce warehouse. Your job is to grade tomatoes, and then teach an artificial intelligence to do the grading for you. Before you start, here are the big ideas you will be using. You do not need any coding experience; you just need to understand how machines learn from examples.
How does a machine learn?
Think about how a young child learns what a dog is. Nobody hands them a rulebook. Instead, an adult points at animals and says βdog... dog... not a dog... dog.β After enough labeled examples, the child spots the pattern and can recognize a dog they have never seen before.
Machine learning works the same way. Instead of being given strict rules, the computer is shown many labeled examples and figures out the pattern on its own. The branch of AI you will use today, learning from labeled examples, is called supervised learning.
In one sentence
Supervised learning is teaching a computer by showing it many examples that already have the correct answer attached.

Training data and labels
The examples you show the AI are called the training data. Each example comes with a label, the correct answer. When you grade a tomato βGrade A,β you are creating one piece of labeled training data: the tomato is the example, and βGrade Aβ is the label. The AI cannot see what you see or taste anything. It only knows what you tell it through your labels. This leads to one of the most important rules in all of AI:
Garbage in, garbage out
An AI is only as good as the data it learns from. If your labels are messy, inconsistent, or biased, the AI will copy those same mistakes, and it will do so confidently.
Features: the clues the AI looks at
To make a decision, the AI breaks each tomato down into features, the measurable clues that might matter. In this activity the features are:
| Feature | Possible values |
|---|---|
| Color | Deep red, orange-red, yellow, or green (a sign of ripeness) |
| Size | Large, medium, or small |
| Blemishes | None, minor, or major damage |
| Shape | Perfectly round or irregular |
Choosing good features is a real skill. A feature like βday of the week the tomato was pickedβ probably would not help at all, while βamount of visible damageβ clearly matters. The AI can only learn from the features it is given.
Classification: sorting into categories
When an AI sorts things into a fixed set of categories, that task is called classification. Your tomatoes go into three classes, following a real grading standard:
Grade A
Ripe, no blemishes, perfect shape. Sold at premium price.
Grade B
Minor flaws. Sold at a discount.
Reject
Unripe or badly damaged. Sent to compost.
Spam filters (spam vs. not spam), medical scans (healthy vs. concerning), and photo apps that tag your friends are all doing classification, just with different categories.

Training vs. testing
It is easy for an AI to memorize examples it has already seen. The real test is whether it can handle something new. That is why machine learning splits the data into two parts:
Training set (12 tomatoes)
The examples the AI learns from. You grade these.
Test set (6 tomatoes)
Fresh examples the AI has never seen, used to measure how well it really learned. The AI grades these.
If the AI does well on the test set, it has learned a genuine pattern rather than memorized answers. This is exactly how engineers check whether an AI is ready for the real world.
Where this happens in real life
This is not a made-up scenario. Companies like Driscoll's and Amazon Fresh use computer vision AI on conveyor belts to grade fruit at high speed. Human inspectors first label thousands of produce photos; the AI learns from those labels and then sorts produce far faster than a person could. The same label-train-test process powers AI that reads medical scans, inspects car parts for defects, and helps self-driving cars recognize stop signs.
Key vocabulary
| Term | What it means |
|---|---|
| Artificial Intelligence (AI) | Computer systems that perform tasks we usually think require human intelligence. |
| Machine learning | A type of AI that learns patterns from examples instead of following hand-written rules. |
| Supervised learning | Machine learning that uses labeled examples (each one comes with the correct answer). |
| Training data | The collection of labeled examples an AI learns from. |
| Label | The correct answer attached to an example (for example, "Grade A"). |
| Feature | A measurable clue about an example that the AI uses to decide (color, size, etc.). |
| Classification | Sorting examples into a fixed set of categories or classes. |
| Test set | New, unseen examples used to measure how well the AI actually learned. |
| Accuracy | The percentage of examples the AI grades correctly. |
Part 2: Fresh Sort: The Harvest QC Challenge
You're a quality inspector at a tomato warehouse. First, you'll grade 12 tomatoes yourself as Grade A, Grade B, or Reject. This teaches the AI your standards. Then the AI will try to grade 6 brand-new tomatoes on its own, and you'll see how well it learned from you.
Grade carefully and consistently: the AI only knows what you teach it!
FreshSort QC Β· sound plays after you press Play
Tip: Play twice. Grade carefully the first time, then grade inconsistently on purpose and compare the AI's accuracy.
Part 3: Real-Life Applications
Now that you have trained your own produce-grading AI, use what you saw to think about how these ideas show up in the real world. Answer in complete sentences and full paragraphs. There is often no single βrightβ answer; your reasoning is what matters.
Real-life scenarios to consider
Example A
The hospital scanner
A hospital uses an AI trained on thousands of chest X-rays that radiologists labeled as "normal" or "needs review." The AI flags scans for a doctor to double-check. It was trained mostly on images from adult patients.
Example B
The resume sorter
A large company builds an AI to sort job applications into "interview" and "pass." It is trained on 10 years of the company's past hiring decisions, which were made by human managers.
Example C
The self-checkout produce camera
A grocery store installs a camera at self-checkout that identifies fruits and vegetables so shoppers don't have to type codes. It was trained on photos of produce taken in a bright studio.
Check your understanding
Hint: Think about what "memorizing" vs. "learning a pattern" means.
Hint: Think about how the AI gets all of its knowledge from your labels.
Hint: Think about how the test situation might differ from the training situation.
Hint: Think about where the AI's "answers" come from.
Your answers are saved in this browser as you type.
For teachers
Teacher resources
Google Docs. Use File > Make a copy to edit, or File > Download to save as PDF or Word.
Teacher notes
Course alignment. AP Computer Science Principles (2027-28 framework), Unit 4: Making Data-Driven Decisions Using the Internet and AI. Topics: Machine Learning; AI Algorithm Development.
Sequence. Part 1 builds the vocabulary (about 15 minutes), Part 2 is the game (about 5 to 10 minutes per play), and Part 3 is written reflection and discussion (about 20 minutes).
How the AI works. The game trains a Naive Bayes classifier on the student's 12 labels, using eight yes/no features (ripe, near-ripe, unripe, large, small, no blemish, major blemish, perfect shape). For each of the 6 test tomatoes it shows a predicted grade and a confidence percentage for every grade. Students then agree with or override each prediction, and the final accuracy is the share of predictions that matched their own standard.
What to look for in student answers:
- Q1: Training data is what the model learns from; the test set is new data used to check it. Testing on the training tomatoes only shows whether the model memorized them, not whether it learned a pattern that works on new tomatoes.
- Q2: Inconsistent labels give the model contradictory examples, so its predictions and confidence scores get less reliable and accuracy usually drops. The model can only be as consistent as its labels.
- Q3: Real stores have dimmer lighting, plastic bags, hands, and messy backgrounds. A model trained only on studio photos may misidentify produce in those conditions. Strong answers suggest training with photos from real stores.
- Q4: The labels are the company's past decisions, so the model learns to repeat them, including any unfair patterns. Collecting more of the same data would not fix this.
Discussion extension. Example A (adult-only training data) works well for discussing who a model is tested on, and why a human doctor still reviews flagged scans.