Learning algorithms are grouped by the kind of feedback they receive while learning: complete answers, no answers, partial answers or rewards.
Supervised Learning
In supervised learning every training example comes with the correct answer, called the label or target. The algorithm learns a mapping from inputs to outputs and is then used to predict the label of unseen inputs. It is called supervised because the labels play the role of a teacher. Examples are email spam detection, house price prediction and handwritten digit recognition. The two main tasks are classification and regression.
Unsupervised Learning
In unsupervised learning the data has no labels. The algorithm looks for structure by itself: groups of similar items (clustering), simpler representations of the data (dimensionality reduction) or items that often occur together (association rules). A shop that groups its customers by buying behaviour, without being told the groups in advance, uses clustering.
Semi-Supervised Learning
Labelling data is slow and costly, but unlabelled data is plentiful. Semi-supervised learning uses a small amount of labelled data and a large amount of unlabelled data together. A common method trains a model on the labelled part, uses it to guess labels for the rest, and retrains. Medical imaging, where only a few scans are annotated by doctors, is a typical use.
Reinforcement Learning
In reinforcement learning an agent interacts with an environment. At each step it takes an action, observes the new state and receives a reward (which may be negative). Its aim is to learn a policy, a rule for choosing actions, that maximises the total reward over time. There are no labelled examples; the agent learns by trial and error. Game-playing programs, robot control and ad placement use reinforcement learning.
Definition: Supervised learning. Learning from a dataset in which every example has a known label, so that the model can predict the label of new, unseen examples.
Table 1.2: Four types of machine learning
| Type | Data | Goal | Example |
|---|---|---|---|
| Supervised | Labelled | Predict the label | Spam detection |
| Unsupervised | Unlabelled | Find structure | Customer clustering |
| Semi-supervised | Few labelled, many unlabelled | Learn with little labelling | Medical scan labelling |
| Reinforcement | Rewards from an environment | Maximise total reward | Game-playing agent |
Example 1.2: Choosing the learning type
Problem: Name the type of learning for (a) predicting a student's marks from study hours using past records, (b) grouping 1000 news articles by topic with no categories given, (c) a robot learning to walk from a reward for each step forward.
Solution:
- (a) Past records contain the true marks, so the data is labelled: supervised learning (regression).
- (b) No categories are given, so the data is unlabelled: unsupervised learning (clustering).
- (c) The robot gets rewards for its actions and no labels: reinforcement learning.
Result: (a) supervised, (b) unsupervised, (c) reinforcement.
from sklearn.neighbors import KNeighborsClassifier
from sklearn.cluster import KMeans
X = [[1, 1], [1, 2], [2, 1], [8, 8], [8, 9], [9, 8]]
y = [0, 0, 0, 1, 1, 1]
knn = KNeighborsClassifier(n_neighbors=3).fit(X, y)
print("Supervised : [2,2] ->", knn.predict([[2, 2]])[0],
" [8,7] ->", knn.predict([[8, 7]])[0])
km = KMeans(n_clusters=2, n_init=10, random_state=0).fit(X)
groups = {}
for i, c in enumerate(km.labels_):
groups.setdefault(c, []).append(i)
print("Unsupervised:", sorted(groups.values()))
Output
Supervised : [2,2] -> 0 [8,7] -> 1
Unsupervised: [[0, 1, 2], [3, 4, 5]]
Common mistakes
- Calling clustering supervised because the output looks like groups.
- Assuming semi-supervised learning needs no labels at all; it needs a few.
- Expecting reinforcement learning to use a labelled training set.
- Forgetting that a reward may be delayed, not immediate.
Key takeaways
- Supervised: labels given. Unsupervised: no labels.
- Semi-supervised: few labels plus many unlabelled examples.
- Reinforcement: agent, environment, action, state, reward, policy.
- Supervised tasks are regression and classification.
Practice questions
- What distinguishes supervised from unsupervised learning?
- What does a reinforcement learning agent try to maximise?
- Why use semi-supervised learning?
Answers to the practice questions
- Supervised data has labels; unsupervised data has none.
- The total reward over time.
- Labelling is costly, so it uses a few labels with many unlabelled examples.
Sources
- Official BCA syllabus Introduction to Machine Learning, course code 26BCA404DSE21, Unit I
