Machine Learning Basics
What Is Machine Learning?
In this lesson you will
- Explain how machine learning differs from ordinary programming
- Name the three main kinds of machine learning
- Give an everyday example of each
Introduction
How does your email know which messages are spam? Nobody wrote a rule for every possible spam message. Instead, a program studied many examples and learned the patterns. This is machine learning (often shortened to ML).
The simple explanation
In ordinary programming you write the rules. In machine learning the computer finds the rules from examples.
- Ordinary programming: data plus rules gives answers. You write rules such as "if the price is over 100, add a delivery fee".
- Machine learning: data plus answers gives rules. You show the computer many examples with the right answers, and it works out a pattern, called a model, that it can apply to new cases.
Quick quiz
What is the main idea of machine learning?
Three main kinds
- Supervised learning learns from examples that already have the right answer (called labels). Example: photos labelled "cat" or "dog", so the model can label a new photo. Predicting a house price from past sales is also supervised.
- Unsupervised learning looks for structure in data that has no labels. Example: grouping customers with similar shopping habits.
- Reinforcement learning learns by trial and error, getting rewards for good actions. Example: a program learning to play a game by playing it many times.
A tiny example
Libraries such as scikit-learn make simple models short to write. This is shown for reading, not for running here. It teaches a model that the answer is double the input, then asks for a new case:
Python
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit([[1], [2], [3]], [2, 4, 6]) # learn from examples
print(model.predict([[4]])) # prints a value very close to 8Nobody told the model "multiply by two". It found that pattern in the examples.
Try it yourself
Think of something you do every day that a computer might learn to predict, such as which song you will skip. What examples would it need, and what would the "right answer" be?
Summary
- Machine learning finds rules from examples instead of having people write them.
- The main kinds are supervised, unsupervised and reinforcement learning.
- A model is the pattern the computer learned, and it is applied to new data.
Lesson complete
+20 XP
Nice work. Keep going while it is fresh.
Sources and further reading