Machine learning in one sentence
Machine learning is writing a program that finds a rule from examples, instead of you writing the rule. The AI foundations course showed the idea; this course makes you do it, in Python.
Features and labels
Every example in a data set has:
- Features: what you know. Size of a flat, number of rooms, distance to town.
- Label: what you want to predict. The monthly rent.
| Size (m²) | Rooms | Rent |
|---|---|---|
| 20 | 1 | 100 |
| 40 | 2 | 170 |
| 60 | 3 | 230 |
Here size and rooms are features; rent is the label.
Two kinds of problem
- Regression: the label is a number. Rent, temperature, sales next week.
- Classification: the label is a category. Spam or not spam, ripe or unripe, which crop disease.
Data in Python
Plain lists are enough to start:
sizes = [20, 30, 40, 50, 60] # feature
rents = [100, 130, 170, 190, 230] # label
for size, rent in zip(sizes, rents):
print(size, "m² rents for", rent)
zip() walks through two lists side by side, giving one pair each time.
Look before you learn
Before any model, look at the data. Here, as size goes up by 10, rent goes up by roughly 30 to 40. A straight line should fit well. That is the next lesson.
Guided practice
A farmer records rainfall (mm), fertiliser (kg) and harvest (bags), and wants to predict the harvest. What are the features and the label, and which kind of problem is it?
Features: rainfall and fertiliser. Label: harvest. The label is a number, so it is regression.