Sub topic 4
The main ways a model can learn
This chapter assumes you know the terms from the previous chapter: an example is one row of data, a feature is an input column, and a label is the answer you want to predict. You should also be able to read short Python and run scikit-learn code. No new math is needed.
A learning paradigm is a way of organizing learning by what kind of feedback the model receives while it trains. The paradigm decides what data you must collect, what the model can output, and how you judge success. Choosing a paradigm is usually the first real design decision in a machine learning project, and it comes before choosing an algorithm.
The question that separates paradigms
Every paradigm answers one question: what tells the model that it is getting better?
- In supervised learning, a label supplies the correct answer for each example.
- In unsupervised learning, no answer is supplied. The model looks for structure in the features alone.
- In reinforcement learning, an environment returns a reward after the model acts.
- Semi-supervised and self-supervised learning mix or manufacture these signals.
The feedback signal is the part that varies. The rest of the training process is the same: the model has parameters, a measure of how wrong it is, and a procedure that adjusts the parameters to reduce that error. The chapter on training covers this procedure in detail.
Supervised learning
In supervised learning, each training example is a pair: features x and a label y. The model learns a function that maps x to y, then uses it on new examples where y is unknown.
The word "supervised" refers to the labels acting like a teacher. After each prediction, the training procedure can compare the model's output to the right answer and compute an error.
Supervised problems split by the type of label:
- Classification predicts a category, such as spam or not spam.
- Regression predicts a number, such as the price of a house.
Supervised learning is the most widely used paradigm in production systems, because many business questions have the form "given what I know now, predict this outcome." Its main cost is labels. Someone or something must produce a correct answer for every training example, and that can be slow, expensive, or biased.
Unsupervised learning
In unsupervised learning, the data has features and no labels. There is no right answer to compare against, so the model's job is to describe the data itself.
Two tasks cover most uses:
- Clustering groups similar examples together, such as customers with similar purchase histories.
- Dimensionality reduction summarizes many features with fewer, which helps with visualization and compression.
Other tasks exist, such as anomaly detection (flagging examples unlike the rest) and density estimation (modeling how likely each example is). The common point is that the output is a description of structure, not a prediction of a known target.
Because there is no ground truth, evaluation is harder. You cannot compute accuracy against labels that do not exist. You judge a clustering by whether the groups are useful, stable, and interpretable, or by how well it supports a later task.
The same data, two paradigms
The iris dataset has four measurements per flower and a species label. The code below uses it both ways. The supervised model sees y. The unsupervised model is never given it.
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.cluster import KMeans
X, y = load_iris(return_X_y=True)
# Supervised: the labels y are part of training.
classifier = LogisticRegression(max_iter=200).fit(X, y)
print("predicted species:", classifier.predict(X[:5]))
# Unsupervised: only X is passed to fit.
clusterer = KMeans(n_clusters=3, n_init=10, random_state=0).fit(X)
print("cluster ids: ", clusterer.labels_[:5])Compare the two lines of output. The classifier predicts species numbers 0, 1, or 2, and those numbers mean something because they come from the labels. The clusterer also outputs 0, 1, or 2, but these are arbitrary group names. Cluster 0 does not have to correspond to species 0. The clusterer only claims that examples with the same id are similar.
This is a common source of confusion. A cluster id is a name for a group, not a prediction of a known category.
Reinforcement learning
In reinforcement learning, a model (called an agent) acts in an environment. After each action, the environment returns a reward, which is a number that says how good the outcome was. The agent learns a policy, a rule for choosing actions, that maximizes total reward over time.
Three things make this different from supervised learning:
- The feedback is a score, not the correct answer. The agent is told how well it did, not what it should have done.
- Rewards can be delayed. A move in a game may only prove good or bad many steps later.
- The agent's actions change the data it sees next. It must balance trying new actions (exploration) against repeating ones that already worked (exploitation).
Reinforcement learning fits problems with sequential decisions, such as game playing, robot control, and some resource-allocation tasks. It is covered only briefly in this tutorial.
Semi-supervised and self-supervised learning
Two further paradigms exist mainly because labels are costly and unlabeled data is cheap.
Semi-supervised learning uses a small set of labeled examples and a large set of unlabeled ones. The unlabeled data helps the model learn the shape of the feature space, and the labeled data anchors it to the target. It suits cases like medical images, where only a few have been annotated by experts.
Self-supervised learning creates labels from the data itself. For example, hide a word in a sentence and train the model to predict it, or hide part of an image and predict the missing part. The "label" is a piece of the input that was held back. No human annotation is needed, so the approach scales to very large datasets. It is the main way large language models are pretrained. The mechanics resemble supervised learning, because there is a target and an error to reduce, but the data needs no manual labeling.
Comparing the paradigms
| Paradigm | Feedback signal | Typical output | Example task |
|---|---|---|---|
| Supervised | A label for each example | A category or a number | Predict whether a loan defaults |
| Unsupervised | None | Groups, or a compact summary | Segment customers by behavior |
| Semi-supervised | A few labels plus many unlabeled examples | A category or a number | Classify images with few annotations |
| Self-supervised | A target derived from the input | A learned representation | Predict a masked word |
| Reinforcement | A reward after actions | A policy for choosing actions | Train an agent to play a game |
How to tell which paradigm applies
A practical way to decide is to ask a short series of questions about your data and your goal.
The diagram is a heuristic, not a rule. Real projects often combine paradigms. A common pattern is to learn a compact representation with unsupervised or self-supervised methods, then train a supervised model on top of it.
Common errors
Several mistakes recur when people first choose a paradigm.
- Treating clusters as labels. Cluster ids are arbitrary, and a different random seed can reorder them. Do not compare them to class labels directly without a matching step.
- Using supervised learning when the labels do not measure what you care about. A model trained to predict "clicked" learns to predict clicks, not satisfaction. The label defines the problem, so a poor label yields a well-trained model for the wrong task.
- Expecting unsupervised learning to find the categories you have in mind. Clustering finds whatever structure the features and the algorithm favor. That structure may split the data by a variable you consider irrelevant.
- Assuming more data always substitutes for labels. Unlabeled data helps only when its structure relates to the target. If it does not, it adds cost without benefit.
- Choosing reinforcement learning for a prediction problem. If you have historical examples with known outcomes, supervised learning is usually simpler, cheaper, and easier to evaluate.
What comes next
The next chapters take the first two paradigms in turn. Supervised learning is covered first, with classification and regression, followed by how training works and how to detect overfitting. The tutorial then covers unsupervised learning, with clustering and dimensionality reduction. A later chapter returns to the decision of which approach fits a given problem, and a final short chapter revisits semi-supervised, self-supervised, and reinforcement learning.
Exercise
A company has two years of support tickets. Each ticket has its text and a tag assigned by an agent, such as "billing" or "bug". The company wants to tag new tickets automatically. A second team has the same tickets but no tags, and wants to discover what topics customers write about. Which paradigm fits each team, and what does the output of each look like?
Show answer
The first team has labels and a known target, so it should use supervised learning, specifically classification. The output is one of the existing tags for each new ticket. The second team has no labels and wants to find structure, so it should use unsupervised learning, such as clustering the ticket text. The output is groups of similar tickets, identified by arbitrary ids. A person must read the groups and decide what topic each one represents.
Exercise
You run KMeans twice on the same data with different random seeds. Both runs produce three clusters, but the ids of the groups differ between runs. Does this mean one run is wrong?
Show answer
Not necessarily. Cluster ids are arbitrary names, so the same grouping can appear with ids permuted. To compare runs, check whether the same examples are grouped together, ignoring the id numbers. A metric such as the adjusted Rand index does this. Differences in which examples are grouped together, not in the id numbers, indicate that the result is unstable.