Lesson 4 of 5 15 min read
What AI and machine learning mean
Understand the difference between AI, machine learning and deep learning, and how a model learns from data.
In this lesson you will
- Define artificial intelligence, machine learning and deep learning and how they relate
- Describe supervised and unsupervised learning
- Explain training, testing and prediction using a simple example
Three terms, one family
Each inside the previous: Artificial intelligence contains Machine learning contains Deep learning
- Artificial intelligence (AI) is the broad goal of making computers perform tasks that normally need human intelligence, such as understanding language, recognising images or planning.
- Machine learning (ML) is the most successful approach to AI today. Instead of programmers writing every rule, the system learns patterns from data.
- Deep learning is a kind of machine learning that uses large neural networks with many layers. It powers image recognition, speech recognition and large language models.
Rules versus learning
Suppose you want to flag spam emails. A traditional program needs hand-written rules:
def is_spam(subject):
return "free money" in subject.lower() or "winner" in subject.lower()Spammers quickly change their wording and the rules break. A machine learning approach shows the computer thousands of emails already labelled "spam" or "not spam" and lets it discover which patterns matter.
Kinds of machine learning
| Type | Learns from | Example |
|---|---|---|
| Supervised | Examples with correct answers (labels) | Predicting house prices from past sales |
| Unsupervised | Data without labels, finding structure | Grouping customers with similar buying habits |
| Reinforcement | Rewards and penalties from actions | Training a program to play a game |
Supervised learning is the most common. It solves two kinds of problem: classification (choosing a category, such as spam or not spam) and regression (predicting a number, such as a price).
How a model learns: a tiny example
Imagine data on hours studied and exam scores:
| Hours studied | Score |
|---|---|
| 1 | 52 |
| 2 | 58 |
| 3 | 65 |
| 4 | 71 |
| 5 | 78 |
A model is a mathematical function with adjustable settings called parameters. Here a straight line fits well: score = slope × hours + intercept. Training means finding the parameters that make the line's predictions closest to the real scores.
With the popular scikit-learn library (pip install scikit-learn), that takes a few lines:
from sklearn.linear_model import LinearRegression
hours = [[1], [2], [3], [4], [5]] # inputs (features)
scores = [52, 58, 65, 71, 78] # labels
model = LinearRegression()
model.fit(hours, scores) # training
print(round(model.coef_[0], 2), round(model.intercept_, 2)) # 6.5 45.3
print(round(model.predict([[6]])[0], 1)) # 84.3The model learned that each extra hour adds about 6.5 marks, and it predicts 84.3 for someone who studies 6 hours.
Training and testing
A model can perform well on the data it learned from yet fail on new data, a problem called overfitting. To get an honest measure, data scientists split the data: most of it for training, and a held-out portion for testing. Only performance on the test data tells you how the model is likely to behave in the real world.
Hands-on exercise
For each task, decide whether it is classification, regression or unsupervised clustering, and name what the labels would be (if any): (1) predicting tomorrow's temperature, (2) detecting whether a photo contains a cat, (3) grouping news articles by topic without predefined categories, (4) estimating a used car's price. If you have Python installed, run the scikit-learn example and predict the score for 8 hours of study. Is that prediction realistic? Why might a straight line stop working?
Knowledge check
3 questions • 70% to pass • Practice only, no certificate
Key concepts
- AI is the broad goal; machine learning learns from data; deep learning uses multi-layer neural networks.
- Supervised learning uses labelled examples for classification (categories) or regression (numbers).
- Training adjusts a model's parameters to fit the data; prediction applies the trained model to new inputs.
- Test on held-out data to detect overfitting; data quality limits model quality.
