What is machine learning
Machine learning is a way of getting a computer to do a task by showing it examples instead of writing the rules yourself. You give an algorithm data, it finds patterns in that data, and it uses those patterns to make predictions about data it has not seen before.
Rules versus learning
Suppose you want to flag spam email. The traditional approach is to write rules: if the subject contains "free money", flag it; if the sender is unknown and there are five exclamation marks, flag it. This works for a while, then spammers change their wording and you write more rules, forever.
The machine learning approach is to collect thousands of emails that people have already labelled as spam or not spam, and let an algorithm work out which words and features separate the two groups. When spam changes, you retrain on new examples instead of rewriting logic.
Traditional: rules + data -> answers
Machine learning: data + answers -> rules (a model)The rules the algorithm produces are called a model. Using the model on new data is called inference or prediction.
A first model in six lines
Here is the whole idea in code. We have the sizes of some flats in square feet and their monthly rent. We fit a straight line and use it to guess the rent of a flat we have not seen.
from sklearn.linear_model import LinearRegression
sizes = [[450], [600], [750], [900], [1200]]
rents = [9000, 12000, 15500, 18000, 24500]
model = LinearRegression().fit(sizes, rents)
print(round(model.predict([[1000]])[0]))The model looked at five examples and learned a relationship (roughly Rs 20 per square foot). Every other model on this site is a more sophisticated version of exactly this: examples in, pattern learned, prediction out.
Vocabulary you will see everywhere
- Features (or inputs,
X): the measurable properties of each example. Flat size, number of bedrooms, distance to the metro. - Label (or target,
y): the thing you want to predict. The rent. - Sample (or observation, row): one example, meaning one flat with its features and label.
- Training: the process of finding the model's internal numbers (parameters) from data.
- Model: the learned function that maps features to a prediction.
- Generalisation: how well the model does on data it did not train on. This is the whole point; a model that only memorises its training data is useless.
Where machine learning is used
- Recommendations on shopping and streaming apps
- Fraud detection on card payments
- Voice assistants and translation
- Medical image screening
- Demand forecasting for inventory
- Credit scoring
- Spam and abuse filtering
In every case there is a large pile of past examples and a pattern too complicated or too fast changing to write by hand.
What machine learning is not
It is not magic and it is not always the right tool. If a problem can be solved with a clear rule (is the order total above the free shipping threshold?), write the rule. Machine learning earns its complexity when the mapping from inputs to outputs is fuzzy, high dimensional, or keeps shifting.
It also needs data. A model cannot learn a pattern that is not in the examples you give it, and it will happily learn biases and mistakes that are.
How this track works
The lessons go from data handling, through the classic supervised and unsupervised algorithms, to a small neural network, and end with a complete project. Each algorithm gets three things: the intuition, the maths written plainly, and scikit-learn code that runs in the page. The first run of any lesson that imports scikit-learn takes a little longer while the library downloads to your browser.
Practice
- Think of three tasks from your daily life that are better solved with rules, and three that are better solved with learning from examples.
- In the rent example, add a sixth flat and see how the prediction for 1000 sq ft changes.
