What machine learning really does
Instead of writing the rule yourself, you give the computer examples and let it find the rule. Learn what that means, and what it does not mean.
In 60 seconds
What machine learning really does
Instead of writing the rule yourself, you give the computer examples and let it find the rule. Learn what that means, and what it does not mean.
- You write the rule by hand
- Input + rule → answer
- Good when the rule is clear and short
- Easy to explain every decision
- The computer finds the rule from examples
- Inputs + answers → rule (the model)
- Good when the rule is fuzzy or has many parts
- Needs good examples and honest testing
Learning is searching for the best setting
# Made-up examples: (weight in grams, ripe? 1 = yes, 0 = no)
examples = [(150, 0), (170, 0), (180, 0), (200, 1), (190, 0),
(220, 1), (240, 1), (210, 1), (205, 0), (260, 1)]
best_t, best_mistakes = None, len(examples) + 1
for t in range(140, 281, 10): # try many possible rules
mistakes = 0
for weight, ripe in examples:
guess = 1 if weight >= t else 0
if guess != ripe:
mistakes += 1
if mistakes < best_mistakes:
best_t, best_mistakes = t, mistakes
print("Learned rule: ripe if weight >=", best_t, "grams")
print("Mistakes on the examples:", best_mistakes, "out of", len(examples))The three big families
| Family | What you give it | What it learns | Example |
|---|---|---|---|
| Supervised learning | Examples with right answers (labels) | To predict the answer for new examples | Predict a house's rent; mark an email as spam or not |
| Unsupervised learning | Examples with no answers | Groups or patterns in the data | Group shop customers by how they buy |
| Reinforcement learning | A world to act in and rewards | Which actions earn more reward | A program learning to play a game |
What machine learning is not
- It is not magic. A model only finds patterns that are in the examples. If the examples are wrong or one-sided, the model will be too.
- It does not understand. A model that sorts mangoes has no idea what a mango is. It found a number that separates two groups.
- It is not always needed. If you can write a clear, short rule, write the rule. It is cheaper and easier to explain.
- Past patterns can break. A model learned from last year's data may fail when things change, for example a new variety of mango.
Watch and read more
Lab
A hand-made rule and a learned straight line for made-up study data, with their average errors side by side.
The problem
The starter makes made-up data: hours studied and marks for 30 imaginary students. It already has a hand-made rule. Your job:
- Run the starter and read the hand rule's average error.
- Use
np.polyfit(hours, marks, 1)to learn a straight line. Store the results inslopeandintercept. - Compute
learned_mae: the mean absolute error of the learned line on the same data. - Store the learned line's prediction for 7 hours in
pred_7. - Compare the two errors. Write one sentence on why the learned line does better.
Practice lab
Edit the code and run it. Python runs in your browser — nothing is sent to our server.
No output. Add print(...) to see values.
You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1The learned line has a smaller error on these 30 students. Does that prove it will do better on new students?Reveal
No. It was chosen to fit these exact 30 points, so its error here is a little optimistic. To know how it does on new students, you must test it on students it did not see during fitting. That is the idea behind train and test sets, later in this track.
Q2Why is the data clipped to 0–100, and could that bend the straight line?Reveal
Marks cannot go below 0 or above 100, so clipping keeps the made-up data realistic. Near the edges, clipping flattens the points, and a straight line cannot bend to follow that. Here few points hit the limits, so the effect is small, but it is a reminder that a straight line is a choice, not a law.
Questions people ask
Is machine learning the same as AI?
Machine learning is one way of building AI, and today it is the main one. AI is the bigger idea of computers doing tasks that seem to need intelligence. Some older AI used only hand-written rules.
Do I need a lot of maths?
To use the methods in this track, you need school-level ideas: averages, a straight line, percentages. To invent new methods you need more, but you can go far with good habits and clear thinking.
How many examples do I need?
There is no fixed number. Simple patterns with little noise need few examples. Complex patterns need many. The honest answer comes from testing: if the model does well on examples it has never seen, you have enough for now.
Why not just write rules by hand every time?
For some problems the rule has hundreds of small parts, like recognising handwriting. Nobody can write that by hand. Learning from examples finds those parts for you.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.