Session 1 of 5 · 60 minutes
What Is Machine Learning?
Understand how a computer can learn from examples instead of rules, then train your first model in the browser.
Goals
By the end of this session you can:
- Explain the difference between following rules and learning from examples
- Name the parts of a machine learning problem: data, features, labels and a model
- Explain why we split data into training and testing sets
- Train and test an image classifier with Google Teachable Machine
Words to know
- machine learning (ML)
- Teaching a computer to find patterns in examples so it can make predictions on new things.
- data
- The examples we learn from: photos, numbers, words, sounds.
- label
- The right answer attached to an example, like "cat".
- model
- The thing that is learned. You give it new input and it gives a prediction.
- training
- Showing the model many labeled examples so it can find the pattern.
- testing
- Checking the model on examples it has never seen.
The lesson
Step 1: Rules versus examples
How would you teach a computer to recognize a cat in a photo? You might try writing rules: “has pointy ears, has whiskers, has fur…” But a cat can be sleeping, hiding or half out of the frame, and the rules quickly fall apart.
There is another way. Show the computer thousands of photos and tell it which ones contain cats. Let it find the pattern itself. That is machine learning.
Some problems are better for rules:
def km_to_miles(km):
return km * 0.621371
print(km_to_miles(10))6.21371A formula is exact and always right. Machine learning is for problems where the rules are too hard to write down: recognizing faces, understanding speech, recommending a video.
Step 2: The parts of a machine learning problem
Every ML project has the same four ingredients.
| Part | What it is | Example: email spam |
|---|---|---|
| Data | The examples | 10,000 emails |
| Features | The facts about each example | Does it say “free money”? How many links? |
| Labels | The right answers | spam / not spam |
| Model | What is learned | A tool that predicts spam or not spam for a new email |
The process is: collect data, train a model on labeled examples, then use it on new data it has never seen.
Step 3: Training and testing
Imagine you study with flashcards. If your test uses the same flashcards, a perfect score doesn’t prove you learned anything, because you may have memorized them. A fair test uses new questions.
Machine learning works the same way. We split our data:
- Training set: examples the model learns from (usually about 70 to 80%).
- Testing set: examples kept hidden until the end, used to check how well it learned.
If a model does great on training data but poorly on testing data, it has memorized instead of learned. We will see this again in Session 5.
Step 4: Teachable Machine
Google Teachable Machine lets you train a model in your browser. Here is the workflow you will follow in the project:
- Choose Image Project, then Standard image model.
- Create classes. Each class is one label, like “pencil”.
- Add samples to each class with the webcam or by uploading images.
- Click Train Model. The computer looks for what is different between your classes.
- Use Preview to test the model on something new.
Tips for a good model: Take many pictures. Change the angle, the distance and the background. Include different lighting. The more variety, the better the model learns the real difference.
Step 5: What the model really knows
Your model doesn’t understand pencils. It found numbers that tend to be different between your pencil photos and your eraser photos. If something new has similar numbers, it says “pencil”.
That is why it can be confidently wrong. If you show it a banana, it will still say “pencil” or “eraser”, because those are the only answers it knows. Good ML practitioners always ask: what examples did this model see, and what did it never see?
Think about it: If you trained a model only with photos of people with one hair color, how might it behave with someone different? We will come back to this in Session 5.
Exercise
Rules or learning?
- Pick three everyday tasks: for example, spotting spam email, recognizing a friend's face, and converting kilometers to miles.
- For each one, decide: could you write simple rules for it, or is it easier to learn from examples? Write one sentence explaining your choice.
- Share your list with a partner. Do you agree on all three?
Need a hint?
If you can write down exact steps that always work (like a formula), use rules. If the pattern is hard to describe, use examples.
Small project
Train your own image classifier
Use Google Teachable Machine to teach the computer to tell two kinds of things apart. No coding needed.
- Go to teachablemachine.withgoogle.com and choose Get Started, then Image Project, then Standard image model.
- Rename the two classes to two things you can show, for example
pencilanderaser, orthumbs upandthumbs down. - Add at least 30 example images to each class using your webcam or by uploading photos. Vary the angle and the background.
- Click Train Model and wait. Then use the Preview panel to test it with something new.
- Write down: how well did it work? What made it get confused? What would improve it?
Stretch it: Add a third class, nothing, showing only the empty background. See what happens to the accuracy.
Quiz
Check your understanding
Pick one answer for each question. Your score appears right in the page; nothing is sent anywhere.
Feedback on this lesson
Teachers and students: tell us what worked and what didn't. We read this to improve the curriculum.
Received
Thank you for the feedback.
The Education team reviews lesson feedback to improve the curriculum.
Preview mode: this form is not connected to a destination yet, so nothing was sent. Set its web address in src/data/config.json.