
Machine learning algorithms are usually grouped by how they learn, and in particular by what kind of feedback they get during training. In supervised learning the model learns from examples labeled with the right answers. In unsupervised learning it gets only raw data and has to find structure on its own. In reinforcement learning an agent learns by trial and error from rewards. Between the first two sit semi-supervised learning, which combines a few labels with a lot of unlabeled data, and self-supervised learning, which creates labels from the data itself and is how large language models are pretrained.
This guide explains each type with examples, compares supervised and unsupervised learning side by side, runs all of them in Python on the same dataset so you can see the difference in numbers, and shows how modern AI systems such as ChatGPT combine several types in one training pipeline.
Key takeaways
- Supervised learning uses labeled data (input plus correct output) and solves classification and regression tasks: spam filters, image recognition, price prediction.
- Unsupervised learning uses unlabeled data and finds patterns: clustering, anomaly detection, association rules and dimensionality reduction.
- Semi-supervised learning trains on a small labeled set plus a large unlabeled one, which matters when labels are expensive, as in medical imaging.
- Self-supervised learning hides part of the data and learns to predict it, for example the next word in a text; it powers foundation models.
- Reinforcement learning has no dataset of answers: an agent acts in an environment and learns a policy that maximizes long-term reward. It is used in games, robotics and RLHF for chatbots.
The Types of Machine Learning at a Glance
| Type | Training data | Feedback | Typical tasks | Example algorithms |
|---|---|---|---|---|
| Supervised | Labeled examples | Correct answer for every example | Classification, regression | Linear and logistic regression, decision trees, gradient boosting, neural networks |
| Unsupervised | Unlabeled data | None | Clustering, anomaly detection, dimensionality reduction, association rules | k-means, DBSCAN, PCA, autoencoders, Apriori |
| Semi-supervised | A few labeled plus many unlabeled examples | Answers for a small part of the data | Classification when labeling is expensive | Label propagation, pseudo-labeling, FixMatch |
| Self-supervised | Unlabeled data, labels made from the data itself | Hidden part of the input | Pretraining language, vision and speech models | GPT (next-token prediction), BERT, contrastive learning, masked autoencoders |
| Reinforcement | Experience gathered by acting in an environment | Reward, often delayed | Games, robotics, control, aligning chatbots | Q-learning, DQN, policy gradients, PPO |
Self-supervised learning is formally a kind of unsupervised learning, because nobody labels the data by hand, but it trains models in the same way as supervised learning, so it is usually discussed separately.
An Analogy: Assembling Furniture
Imagine you have to assemble a cabinet from a flat-pack kit. There are several ways to learn how to do it.
- Supervised: you have the instruction leaflet, or a friend who knows the answer and checks every step. You compare your work with the correct result and fix mistakes. After a few cabinets you can assemble one without help.
- Unsupervised: you get a pile of parts and no instructions. You can still discover structure: sort the screws by size, group the panels by shape, notice that some parts always go together. Nobody tells you what the groups mean.
- Semi-supervised: the leaflet has only a couple of pages left. You use them to understand the main steps and work out the rest by analogy.
- Reinforcement: no instructions and no teacher, but you can try things. When the cabinet stands up and the doors close, that is a reward; when it wobbles or collapses, that is a penalty. Over many attempts you learn which actions lead to a sturdy cabinet, even if the result of an early decision only shows up at the end.
Supervised Learning
In supervised learning the training set consists of pairs: an input x and the correct output y, called the label or target. The model learns a function that maps inputs to outputs, and its errors on the training examples are used to adjust its parameters, for neural networks with backpropagation and gradient descent. The goal is to predict labels correctly for new data the model has never seen.
Labeled data is what makes supervised learning work, and also what makes it expensive. To train a model that recognizes cats, someone has to look through thousands of photos and mark which ones contain a cat; for medical images the labels have to come from doctors.
Classification vs regression
Supervised tasks come in two kinds, depending on the label:
- Classification predicts a category: spam or not spam, which digit is in an image, which of 1,000 object classes is in a photo. The model usually outputs a probability for each class.
- Regression predicts a number: the price of a house, tomorrow’s temperature, the number of sales next month. The classic algorithm is linear regression.
Computer vision has several supervised tasks of growing difficulty. A classifier says what is in the picture; localization also draws a box around it; object detection finds every object with its class and box; segmentation labels every pixel. Each needs more detailed labels:

Supervised learning examples
- Email spam filters trained on messages marked as spam or not spam.
- Image recognition: classifying photos, detecting pedestrians for self-driving cars, finding tumors in scans.
- Speech recognition, trained on audio with transcripts.
- Machine translation, trained on pairs of sentences in two languages.
- Credit scoring and fraud detection, trained on past transactions with known outcomes.
- Demand, price and sales forecasting.
Popular supervised algorithms include linear and logistic regression, naive Bayes, k-nearest neighbors, support vector machines, decision trees, random forests, gradient boosting and neural networks such as convolutional networks for images.
Supervised learning in Python
To compare the types of learning on equal terms, all examples in this guide use the same data: 1,797 handwritten digits, 8×8 pixels each, from scikit-learn. First, a supervised classifier that sees every training image with its label:
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
X, y = load_digits(return_X_y=True) # 1,797 images of 8x8 pixels, labels 0-9
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0, stratify=y)
# Supervised: the model sees every training image together with its label
clf = LogisticRegression(max_iter=5000).fit(X_train, y_train)
print(f"supervised accuracy: {accuracy_score(y_test, clf.predict(X_test)):.3f}")
supervised accuracy: 0.961
With all 1,257 training labels, a simple logistic regression recognizes 96% of the test digits.
Unsupervised Learning
In unsupervised learning there are no labels at all. The algorithm receives only the inputs and has to find structure in them by itself: groups of similar examples, unusual points, a compact representation of the data. Nobody tells it what the right answer is, and often there is no single right answer.

This is useful because most of the world’s data is unlabeled. Clicks, transactions, sensor readings and images pile up much faster than anyone can label them, and unsupervised methods let you explore them before you know what to look for.
Clustering
Clustering splits data into groups so that examples in the same group are more similar to each other than to examples in other groups. Shown a mix of photos, a clustering algorithm can separate cats from cookies without knowing either word, just because the images in each group share features: shapes, colors, textures.

The most popular method is k-means clustering. You choose the number of clusters k; the algorithm places k centers, assigns every point to the nearest center, moves each center to the mean of its points, and repeats until the assignment stops changing. Other methods include hierarchical clustering, DBSCAN, which finds clusters of any shape and marks outliers, and Gaussian mixture models. Businesses use clustering for customer segmentation, grouping documents by topic and organizing image collections.
Anomaly detection
If you know what normal data looks like, you can flag what does not fit: a fraudulent credit card payment, a failing machine in a factory, an intrusion in network traffic. Anomalies are rare and varied, so there are usually too few labeled examples for supervised learning, and unsupervised methods such as isolation forests, one-class SVMs and autoencoders that cannot reconstruct unusual inputs are used instead.
Association rules
Association rule mining finds items that often occur together. The classic example is market basket analysis: customers who buy diapers often buy baby wipes, so the shop can place them together or recommend one with the other. Recommendation systems are built on similar ideas.
Dimensionality reduction
Real data often has hundreds or thousands of features. Dimensionality reduction compresses it into a few features that keep most of the information. Principal component analysis (PCA) finds the directions of greatest variance; t-SNE and UMAP produce 2D maps for visualization. Autoencoders do the same with neural networks: an encoder compresses the input into a small vector and a decoder reconstructs it, and variational autoencoders and GANs go further and learn to generate new data.
Unsupervised learning in Python
Now k-means gets the same digit images, but without labels. We ask it for 10 clusters and then check how well they match the real digits:
import numpy as np
from sklearn.cluster import KMeans
from sklearn.metrics import adjusted_rand_score
# Unsupervised: k-means gets only the pixels, never the labels
km = KMeans(n_clusters=10, n_init=10, random_state=0).fit(X_train)
clusters = km.predict(X_test)
print(f"k-means adjusted Rand index: {adjusted_rand_score(y_test, clusters):.3f}")
# Name each cluster after its most common digit (we peek at labels only to score the result)
names = {c: np.bincount(y_train[km.labels_ == c]).argmax() for c in range(10)}
print(f"k-means accuracy after naming clusters: {accuracy_score(y_test, [names[c] for c in clusters]):.3f}")
k-means adjusted Rand index: 0.641
k-means accuracy after naming clusters: 0.778
The adjusted Rand index compares the clusters with the true classes: 0 means random grouping, 1 a perfect match. A score of 0.64 means that k-means, which never saw a single label, discovered much of the structure of the digits on its own. If each cluster is named after the digit that appears in it most often, 78% of test images land in the right group. That is well below the 96% of the supervised model, because some digits look alike in pixels: most eights share a cluster with ones or nines, and the ones are scattered over several clusters. K-means finds groups of similar images, but similar is not always the same as the categories people care about.
Supervised vs Unsupervised Learning
| Supervised learning | Unsupervised learning | |
|---|---|---|
| Input data | Labeled: input and correct output | Unlabeled: inputs only |
| Goal | Predict the label for new data | Find structure, groups or anomalies |
| Tasks | Classification, regression | Clustering, association, dimensionality reduction, anomaly detection |
| Evaluation | Clear: compare predictions with known answers (accuracy, error) | Harder: no ground truth, results need interpretation |
| Cost of data | High: labeling takes people and time | Low: raw data is plentiful |
| Human involvement | Before training, to label data | After training, to interpret the results |
| Examples | Spam filter, image classifier, price forecast | Customer segments, fraud detection, topic discovery |
In short, use supervised learning when you know what you want to predict and have examples of the answer; use unsupervised learning when you want to understand data you have not labeled, or as a first step before deciding what to label. In practice the two are often combined: clusters found without supervision become features for a supervised model, and PCA is used to shrink the input before classification.
Semi-Supervised Learning
Semi-supervised learning sits between the two. The training set has a small number of labeled examples and a much larger number of unlabeled ones. The labeled examples show what the classes are; the unlabeled ones show how the data is distributed, where the dense regions and natural boundaries lie. The basic assumption is that points close to each other, or in the same cluster, probably share a label.
A typical application is medical imaging. Hospitals have huge archives of scans, but labeling them requires a radiologist’s time. A model trained on a few hundred labeled scans together with tens of thousands of unlabeled ones can be noticeably more accurate than one trained on the labeled scans alone.

Common semi-supervised techniques:
- Label propagation and label spreading build a graph of similar examples and spread the known labels along it to unlabeled neighbors.
- Self-training or pseudo-labeling: train a model on the labeled data, label the unlabeled data with its most confident predictions, add those to the training set and repeat.
- Consistency regularization: require the model to give the same prediction for different augmented versions of the same unlabeled image. FixMatch combines this with pseudo-labeling.
- Semi-supervised GANs: the discriminator of a GAN classifies images not just as real or fake but into the real classes plus a “fake” class. Learning to spot fakes on unlabeled data helps it learn features that also improve classification.

Semi-supervised learning in Python
Let us hide the labels of all but 30 training digits, about three per class, and compare a supervised model trained on those 30 images with label spreading, which also uses the 1,227 unlabeled images:
from sklearn.semi_supervised import LabelSpreading
# Semi-supervised: keep labels for only 30 training images, mark the rest as unlabeled (-1)
rng = np.random.RandomState(0)
labeled = rng.choice(len(y_train), 30, replace=False)
y_partial = np.full_like(y_train, -1)
y_partial[labeled] = y_train[labeled]
only_labeled = LogisticRegression(max_iter=5000).fit(X_train[labeled], y_train[labeled])
spread = LabelSpreading(kernel="knn", n_neighbors=7).fit(X_train, y_partial)
print(f"30 labels, supervised only: {accuracy_score(y_test, only_labeled.predict(X_test)):.3f}")
print(f"30 labels + 1,227 unlabeled: {accuracy_score(y_test, spread.predict(X_test)):.3f}")
30 labels, supervised only: 0.796
30 labels + 1,227 unlabeled: 0.915
Unlabeled images raise accuracy from 80% to 92%. Repeating the experiment with different numbers of labels shows that the benefit is largest when labels are scarce and fades as the labeled set grows:

With 10 to 30 labels, semi-supervised learning is 13 to 17 percentage points more accurate. With all 1,257 labels the gap almost disappears, because the unlabeled data no longer adds much.
Self-Supervised Learning
Self-supervised learning removes the need for human labels by turning the data into its own teacher. Part of the input is hidden, and the model is trained, exactly as in supervised learning, to predict the hidden part from the rest:
- Next-token prediction: GPT-style language models read trillions of words of text and learn to predict each next word. Every position in every document is a free training example.
- Masked modeling: BERT predicts words removed from a sentence; masked autoencoders reconstruct hidden patches of an image.
- Contrastive learning: methods such as SimCLR and CLIP learn that two views of the same image, or an image and its caption, belong together, and that unrelated pairs do not.
The model does not learn a task anyone cares about directly, but to predict the missing part it has to learn grammar, facts, the shapes of objects and much more. The result is a foundation model that can then be adapted to specific tasks with a small amount of labeled data. Yann LeCun has compared machine learning to a cake: self-supervised learning is the bulk of the cake, supervised learning the icing, and reinforcement learning the cherry on top.
Reinforcement Learning
Reinforcement learning (RL) is different from all the types above: there is no fixed dataset at all. An agent interacts with an environment. At each step it observes the state, chooses an action and receives a reward, a number that says how good the outcome was, and the environment moves to a new state. The agent’s goal is to learn a policy, a rule for choosing actions, that maximizes the total reward over time.
Nobody tells the agent which action was correct. It only learns how well things went, and often much later. In chess, the reward comes at the end of the game, so the agent must work out which of the many earlier moves led to the win. This is called the credit assignment problem, and it is why RL agents have to learn long-term strategy rather than just the best immediate move. They sometimes have to accept a short-term loss, like a chess sacrifice, for a bigger reward later.
The agent also faces the exploration-exploitation trade-off: it should use the actions it already knows are good, but it also needs to try new ones, which may turn out to be better. A common simple rule, epsilon-greedy, picks a random action with a small probability and the best known action otherwise.

Reinforcement learning examples
- Games: DeepMind’s DQN learned to play Atari games from screen pixels; AlphaGo beat world champion Lee Sedol at Go in 2016; AlphaZero learned chess, shogi and Go purely by playing against itself.
- Robotics: walking, grasping and manipulating objects, often learned in simulation first and transferred to real robots.
- Autonomous driving and control: driving policies in simulators, cooling data centers, controlling plasma in fusion reactors.
- Recommendation and advertising: choosing what to show to maximize long-term engagement.
- Language models: RLHF and training of reasoning models, described below.
Q-learning in Python
Q-learning is a classic RL algorithm. It keeps a table Q[state, action] with an estimate of the total future reward for taking an action in a state, and after each step moves the estimate towards the reward received plus the discounted value of the best action in the next state. Here an agent learns to walk from the start S to the goal G in a small grid. Every move costs 1 point, reaching the goal gives 10, and stepping on the cliff X costs 10 and ends the episode:
import numpy as np
# A 4x6 grid world: S = start, G = goal (+10), X = cliff (-10, episode ends), every move costs -1
grid = ["......",
"......",
"......",
"SXXXXG"]
rows, cols = len(grid), len(grid[0])
moves = [(-1, 0), (0, 1), (1, 0), (0, -1)] # up, right, down, left
arrows = "^>v<"
def step(state, action):
r, c = state
dr, dc = moves[action]
r, c = min(max(r + dr, 0), rows - 1), min(max(c + dc, 0), cols - 1)
cell = grid[r][c]
if cell == "G":
return (r, c), 10, True
if cell == "X":
return (r, c), -10, True
return (r, c), -1, False
rng = np.random.default_rng(0)
Q = np.zeros((rows, cols, 4)) # expected future reward of each action in each cell
alpha, gamma, epsilon = 0.5, 0.95, 0.1
rewards = []
for episode in range(500):
state, done, total = (3, 0), False, 0
while not done:
# explore with probability epsilon, otherwise exploit the best known action
action = rng.integers(4) if rng.random() < epsilon else int(Q[state].argmax())
next_state, reward, done = step(state, action)
target = reward + (0 if done else gamma * Q[next_state].max())
Q[state][action] += alpha * (target - Q[state][action]) # Q-learning update
state, total = next_state, total + reward
rewards.append(total)
for start in range(0, 500, 100):
print(f"episodes {start + 1:3d}-{start + 100}: average reward {np.mean(rewards[start:start + 100]):6.1f}")
# After training: follow the best action in every cell, no exploration
state, done, total, steps = (3, 0), False, 0, 0
while not done:
state, reward, done = step(state, int(Q[state].argmax()))
total, steps = total + reward, steps + 1
print(f"greedy run: {steps} moves, total reward {total}")
print("learned policy:")
for r in range(rows):
print(" ".join(grid[r][c] if grid[r][c] in "GX" else arrows[Q[r, c].argmax()] for c in range(cols)))
episodes 1-100: average reward -2.9
episodes 101-200: average reward 1.1
episodes 201-300: average reward 0.5
episodes 301-400: average reward 0.6
episodes 401-500: average reward 1.4
greedy run: 7 moves, total reward 4
learned policy:
v v v v v v
v > v > > v
> > > > > v
^ X X X X G
The agent was never shown the route. At first it wanders and falls off the cliff; after a few hundred episodes it has learned the shortest path: one step up, five steps right along the edge of the cliff, and one step down to the goal, for a total reward of 4, the best possible. The average reward during training stays lower because the agent still explores randomly 10% of the time and sometimes falls.
Deep reinforcement learning
A table works only for small problems. In video games or robotics the number of states is astronomical, so deep reinforcement learning replaces the table with a neural network that estimates values or chooses actions directly from images and sensor data. Popular algorithms include DQN, policy gradient methods, actor-critic methods and PPO, which is also widely used for training language models.
How Modern AI Combines All of Them
The types of learning are not rivals: modern AI systems use several of them in sequence. A chatbot like ChatGPT, Claude or Gemini is built roughly like this:
- Self-supervised pretraining: the model learns to predict the next token on a huge amount of text and code, and absorbs language and knowledge.
- Supervised fine-tuning: it is trained on examples of good answers written or checked by people, which teaches it to follow instructions.
- Reinforcement learning from human feedback (RLHF): people compare pairs of answers, a reward model is trained in a supervised way to predict their preferences, and the chatbot is then optimized with reinforcement learning to get high reward. OpenAI’s InstructGPT made this approach standard in 2022.
- Reinforcement learning with verifiable rewards: since OpenAI’s o1 and DeepSeek-R1 in 2024 and 2025, reasoning models are also trained with RL on math and coding problems whose answers can be checked automatically, which teaches them to think step by step.
Other fields follow similar patterns. Self-driving cars use supervised perception models trained on labeled camera and lidar data, self-supervised pretraining on unlabeled video, and reinforcement learning in simulation for planning. Vision models are pretrained on unlabeled images and fine-tuned on a few labeled ones, which is semi-supervised learning in spirit.
Which Type of Learning Should You Use?
- You know the target and have enough labeled examples: supervised learning. Start with simple models such as logistic regression or gradient boosting for tabular data, and neural networks for images, sound and text.
- You have data but no labels and want to explore it: unsupervised learning. Try clustering to find segments, PCA or UMAP to visualize, anomaly detection to find outliers.
- You have a few labels and much more unlabeled data: semi-supervised learning, or fine-tune a pretrained foundation model, which is often the simplest option today.
- The problem is a sequence of decisions with a measurable goal, and you can simulate or safely try actions: reinforcement learning.
- You need a general model of language, images or audio: do not train from scratch; use a model pretrained with self-supervised learning.
FAQ
What is the main difference between supervised and unsupervised learning?
Supervised learning trains on labeled data, where every example comes with the correct answer, and learns to predict that answer for new data. Unsupervised learning trains on unlabeled data and finds patterns, such as clusters or anomalies, without being told what to look for.
What are the main types of machine learning?
The three classic types are supervised, unsupervised and reinforcement learning. Semi-supervised learning, which mixes labeled and unlabeled data, and self-supervised learning, which makes labels from the data itself, are often added as separate types.
Is reinforcement learning supervised or unsupervised?
Neither. It does not learn from correct answers like supervised learning, and it is not just finding patterns like unsupervised learning. An agent learns from rewards it receives for its own actions, so reinforcement learning is considered a separate type.
Is k-means supervised or unsupervised?
K-means is unsupervised. It groups data points into clusters based only on their features and never uses labels.
Is linear regression supervised or unsupervised?
Supervised. Linear regression learns from examples with known target values, such as house prices, and predicts the target for new examples. Logistic regression, decision trees and neural network classifiers are supervised too.
Are large language models trained with supervised or unsupervised learning?
Both, and more. They are pretrained with self-supervised learning on unlabeled text, then fine-tuned with supervised learning on example answers, and finally trained with reinforcement learning from human feedback and from automatically checked rewards.
What is RLHF?
Reinforcement learning from human feedback is a way to align a language model with what people want. Humans rank the model’s answers, a reward model learns to predict these rankings, and the language model is optimized with reinforcement learning to produce answers the reward model scores highly.
See also: our guides to decision trees and gradient boosting, the most popular supervised methods for tabular data, and to variational autoencoders, a neural approach to unsupervised learning.










