Sub topic 4
The Main Ways a Model Can Learn
This chapter assumes you know basic Python, can read arrays of numbers, and understand examples, features, and labels from the previous chapter. It gives a map of the learning paradigms. Later chapters cover each one in detail.
What a paradigm is
A learning paradigm is a way of setting up the learning problem. It is defined by what the model is given and what feedback it gets. The algorithm matters less than this setup. The same data can be used in different paradigms, depending on which columns you treat as labels.
The two core paradigms
Supervised learning uses examples that include the correct answer. Each example has features and a label. The model learns a mapping from features to labels, then predicts labels for new examples. Predicting house prices from size and location is a supervised task.
Unsupervised learning uses examples with features only. No answer is given. The model looks for structure in the data itself, such as groups of similar examples or a compact summary of many features. Grouping customers by purchase behavior is an unsupervised task.
The deciding question is whether you have labels and want to predict them.
Seeing the difference in code
The difference shows up in what you pass to fit. A supervised model receives X and y. An unsupervised model receives only X.
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 = LogisticRegression(max_iter=200).fit(X, y)
unsupervised = KMeans(n_clusters=3, n_init=10, random_state=0).fit(X)
print(supervised.predict(X[:3]))
print(unsupervised.labels_[:3])The first line prints species labels the model learned to predict. The second prints cluster numbers. K-means never saw the species, so its numbers are arbitrary names for groups. A cluster numbered 2 does not have to match species 2.
Other paradigms
Some problems fit neither core setup. Three variants are common.
- Semi-supervised learning uses a small set of labeled examples and a large set of unlabeled ones. It helps when labeling is expensive.
- Self-supervised learning builds labels from the data itself. For example, a model hides a word in a sentence and learns to predict it. No human labeling is needed.
- Reinforcement learning has an agent take actions in an environment and receive rewards. It learns a strategy that maximizes total reward over time.
How they compare
| Paradigm | Input | Feedback | Typical goal |
|---|---|---|---|
| Supervised | Features and labels | Correct answer per example | Predict a label |
| Unsupervised | Features only | None | Find structure |
| Semi-supervised | Few labeled, many unlabeled | Partial answers | Predict with less labeling |
| Self-supervised | Features only, labels made from the data | Generated answer | Learn useful representations |
| Reinforcement | States, actions, rewards | Reward after actions | Choose good actions |
Common errors
- Treating cluster numbers as labels. Cluster ids carry no meaning on their own. You must inspect the groups to interpret them.
- Assuming unsupervised output is "correct". With no labels, there is no answer key. Different settings produce different valid groupings.
- Calling self-supervised learning unsupervised without qualification. It uses no human labels, but it still trains against a target, so it is trained much like supervised learning.
Exercise
You have 50,000 product photos and want to sort them into groups of similar items. No one has tagged them. Which paradigm fits, and what do you pass to fit()?
Show answer
Unsupervised learning, specifically clustering. You pass only the feature array X (for example, image features), with no label array y. If you later tag a small subset and want to predict tags for the rest, semi-supervised learning becomes an option.