Types of Machine Learning
Machine learning algorithms are grouped by how they learn: from labelled answers (supervised), from raw unlabelled data (unsupervised), or from rewards earned by acting in an environment (reinforcement). Knowing the type of problem you face tells you which family of algorithms to reach for.
Supervised learning
In supervised learning every training example comes with the correct answer, called the label. The model learns a mapping from features to label, like a student learning from a past paper with a marking scheme. There are two kinds of supervised problems:
| Task | Predicts | Examples | Typical algorithms |
|---|---|---|---|
| Classification | A category | Spam or not spam; which crop disease is in a photo; will a borrower repay? | Logistic regression, decision trees, KNN, random forests |
| Regression | A number | House rent in KES; tomorrow's maize price; delivery time in minutes | Linear regression, decision trees, random forests |
A quick test: if the answer is a word or class, it's classification; if it's a quantity you could average, it's regression.
from sklearn.tree import DecisionTreeClassifier hours = [[1], [2], [3], [6], [7], [8]] # feature result = ["fail", "fail", "fail", "pass", "pass", "pass"] # label clf = DecisionTreeClassifier(random_state=42) clf.fit(hours, result) print(clf.predict([[2.5], [6.5]]))
The tree learned a single rule from the labels: "hours <= 4.5 means fail". Because we supplied the answers, this is supervised learning.
Unsupervised learning
In unsupervised learning there are no labels. The algorithm looks for structure by itself. Common tasks are:
- Clustering: grouping similar items, such as customer segments for a SACCO (see K-Means Clustering).
- Dimensionality reduction: compressing many features into a few, for visualisation or speed (see PCA).
- Anomaly detection: flagging unusual transactions that don't look like the rest.
Here is the same data with the labels removed. K-means finds two groups on its own:
import numpy as np from sklearn.cluster import KMeans hours = np.array([[1], [2], [3], [6], [7], [8]]) # no labels this time km = KMeans(n_clusters=2, n_init=10, random_state=42) km.fit(hours) print(np.sort(km.cluster_centers_.ravel()))
The algorithm discovered one group centred on 2 hours and another centred on 7 hours. It doesn't know that these groups mean "fail" and "pass"; interpreting clusters is your job.
Reinforcement learning
In reinforcement learning (RL) an agent takes actions in an environment and receives rewards or penalties. Over many attempts it learns a policy, a strategy that maximises total reward. Nobody tells it the right move; it discovers good moves by trial and error, much like learning to ride a bicycle.
- Game-playing systems such as DeepMind's AlphaGo, which beat top professional Lee Sedol at the board game Go in 2016, combined RL with deep learning.
- Robots learning to walk or grasp objects.
- Large language model chatbots are often refined with reinforcement learning from human feedback (RLHF), where human preferences act as the reward signal.
Other types you will hear about
- Semi-supervised learning: a few labelled examples plus many unlabelled ones. Useful when labelling is expensive, such as getting doctors to label X-rays.
- Self-supervised learning: the data provides its own labels. For example, hide the next word of a sentence and ask the model to predict it. This is how large language models are pre-trained.
Don't confuse classification with regression just because labels are numbers. If you code "low", "medium" and "high" risk as 0, 1 and 2, the task is still classification: the numbers are names for categories, not quantities.
Key points
- Supervised learning uses labelled data; it splits into classification (categories) and regression (numbers).
- Unsupervised learning finds structure in unlabelled data: clusters, compressed features or anomalies.
- Reinforcement learning learns a strategy from rewards earned by acting.
- Semi-supervised and self-supervised learning reduce the need for human labels.
Tip: use the ← and → keys to move between pages.
