ai

Types of Machine Learning: Supervised, Unsupervised & Reinforcement

Understand supervised, unsupervised, and reinforcement learning with clear examples, key algorithms, Python code, and a guide to choosing the right ML approach.

By Shubhankar Tripathi • • 5 min read

BitCodeMatrix  |  AI-ML Fundamentals

Types of Machine Learning: Supervised, Unsupervised, and Reinforcement Learning

A practical guide to the three core learning paradigms, how each one works, the algorithms behind them, and when to use which.


What You Will Learn

  • What machine learning is and why it is grouped into types

  • How supervised learning works, including classification and regression

  • How unsupervised learning finds structure through clustering, dimensionality reduction, and association

  • How reinforcement learning agents learn from rewards

  • Popular algorithms, evaluation metrics, and real-world use cases for each type

  • Semi-supervised and self-supervised learning, and how to choose the right approach

Introduction

Machine learning (ML) is the branch of artificial intelligence that enables computers to learn patterns from data instead of following explicitly programmed rules. It powers product recommendations, fraud detection, voice assistants, medical image analysis, and the large language models behind modern AI chatbots.

Not all machine learning works the same way. The most important distinction is how a model learns: whether it is shown the correct answers, whether it must discover patterns on its own, or whether it learns by interacting with an environment and receiving feedback. These three approaches are known as supervised learning, unsupervised learning, and reinforcement learning.

This article explains each type in depth, with examples, common algorithms, evaluation methods, and short Python code samples, so you can recognise which approach fits a given problem.

What Is Machine Learning?

Arthur Samuel, an early pioneer of the field, described machine learning in 1959 as giving computers the ability to learn without being explicitly programmed. A more formal definition from Tom Mitchell (1997) states that a program learns from experience E with respect to a task T and a performance measure P if its performance on T, as measured by P, improves with experience E.

In practice, a machine learning workflow takes historical data, applies an algorithm to learn a model, and uses that model to make predictions or decisions on new data. The type of machine learning is determined mainly by the kind of data and feedback available during training.

Figure 1: The three main types of machine learning and their common sub-tasks

Figure 1: The three main types of machine learning and their common sub-tasks

Quick Overview of the Three Types

Aspect

Supervised

Unsupervised

Reinforcement

Training data

Labelled input-output pairs

Unlabelled data

No fixed dataset; experience from interaction

Feedback

Correct answer for each example

None

Reward or penalty after actions

Goal

Predict labels or values

Discover hidden structure

Maximise cumulative reward

Typical tasks

Classification, regression

Clustering, dimensionality reduction, association

Sequential decision-making, control

Example

Email spam filter

Customer segmentation

Game-playing agent, robotics


1. Supervised Learning

Supervised learning is the most widely used type of machine learning. The model is trained on a labelled dataset, meaning each training example includes both the input features and the correct output, called the label or target. The model learns a mapping from inputs to outputs and then applies it to new, unseen inputs.

The term "supervised" comes from the idea of a teacher supervising the learning process. During training, the algorithm makes predictions, compares them with the correct labels, measures the error using a loss function, and adjusts its parameters to reduce that error.

How Supervised Learning Works

  1. Collect labelled data: Gather examples with known outcomes, such as emails marked "spam" or "not spam".

  2. Split the data: Divide it into training, validation, and test sets so performance can be measured on data the model has not seen.

  3. Train the model: The algorithm learns the relationship between features and labels by minimising a loss function.

  4. Evaluate: Measure performance on the test set using appropriate metrics.

  5. Predict: Use the trained model to predict labels for new data.

Types of Supervised Learning Problems

Classification predicts a discrete category. Binary classification has two possible classes, such as fraud or not fraud. Multi-class classification has more than two, such as identifying whether an image shows a cat, dog, or bird. Multi-label classification allows several labels per example, such as tagging an article with multiple topics.

Regression predicts a continuous numerical value, such as a house price, tomorrow's temperature, or next month's sales.

Common Supervised Learning Algorithms

Algorithm

Used For

Key Idea

Linear Regression

Regression

Fits a straight line (or hyperplane) that minimises squared error

Logistic Regression

Classification

Models the probability of a class using the sigmoid function

Decision Tree

Both

Splits data with a sequence of if-then rules on features

Random Forest

Both

Averages many decision trees trained on random subsets to reduce overfitting

Gradient Boosting (XGBoost, LightGBM)

Both

Builds trees sequentially, each one correcting the errors of the previous ones

Support Vector Machine (SVM)

Both (mainly classification)

Finds the boundary that separates classes with the widest margin

k-Nearest Neighbours (k-NN)

Both

Predicts using the labels of the k most similar training examples

Naive Bayes

Classification

Applies Bayes' theorem, assuming features are independent

Neural Networks

Both

Layers of connected neurons that learn complex, non-linear patterns


Evaluating Supervised Models

  • Classification metrics: accuracy, precision, recall, F1 score, ROC-AUC, and the confusion matrix. Precision and recall matter more than accuracy when classes are imbalanced, such as in fraud detection.

  • Regression metrics: Mean Absolute Error (MAE), Mean Squared Error (MSE), Root Mean Squared Error (RMSE), and R-squared.

  • Validation techniques: train-test split and k-fold cross-validation help confirm that a model generalises rather than memorising the training data.

Supervised Learning Example in Python

The example below trains a Random Forest classifier on the classic Iris flower dataset using scikit-learn and reports its accuracy on held-out test data.

Python: classification with scikit-learn

from sklearn.datasets import load_iris

from sklearn.model_selection import train_test_split

from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import accuracy_score

 

X, y = load_iris(return_X_y=True)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

 

model = RandomForestClassifier(random_state=42)

model.fit(X_train, y_train)

print("Accuracy:", accuracy_score(y_test, model.predict(X_test)))


Real-World Applications of Supervised Learning

  • Email spam filtering and phishing detection

  • Credit scoring and loan default prediction

  • Medical diagnosis from lab results and medical images

  • House price and demand forecasting

  • Speech recognition and image classification

  • Customer churn prediction

Advantages and Limitations

Advantages: clear objectives, measurable accuracy, and strong performance when good labelled data is available. Results are generally easier to validate than in other types of learning.

Limitations: labelling data is often expensive and slow, especially when experts such as doctors are needed. Models can inherit bias from labels and may struggle with situations not represented in the training data.

2. Unsupervised Learning

Unsupervised learning works with data that has no labels. Instead of predicting a known answer, the algorithm explores the data to find hidden patterns, groupings, or structure on its own. It is especially useful when labelling is impractical or when you do not yet know what patterns exist.

Figure 2: Supervised learning uses known labels; unsupervised learning discovers groups without them

Figure 2: Supervised learning uses known labels; unsupervised learning discovers groups without them

Types of Unsupervised Learning Problems

Clustering groups similar data points together so that items in the same cluster are more similar to each other than to items in other clusters. A common example is segmenting customers by purchasing behaviour.

Dimensionality reduction reduces the number of features while preserving as much important information as possible. It is used to compress data, remove noise, speed up training, and visualise high-dimensional data in two or three dimensions.

Association rule learning discovers relationships between items in large datasets, such as "customers who buy bread and butter often also buy milk". This is the basis of market basket analysis.

Anomaly detection identifies data points that differ significantly from the majority, which is useful for spotting fraud, equipment faults, or network intrusions.

Common Unsupervised Learning Algorithms

Algorithm

Task

Key Idea

K-Means

Clustering

Assigns points to k clusters by minimising distance to each cluster centre

Hierarchical Clustering

Clustering

Builds a tree (dendrogram) of nested clusters by merging or splitting groups

DBSCAN

Clustering

Groups dense regions of points and marks sparse points as noise

Gaussian Mixture Models

Clustering

Models data as a mix of Gaussian distributions with soft assignments

PCA

Dimensionality reduction

Projects data onto the directions of greatest variance

t-SNE and UMAP

Dimensionality reduction

Non-linear methods mainly used to visualise high-dimensional data

Apriori and FP-Growth

Association rules

Find item sets that frequently occur together

Isolation Forest

Anomaly detection

Isolates outliers using random splits; anomalies are isolated faster

Autoencoders

Dimensionality reduction, anomaly detection

Neural networks that learn to compress and reconstruct their input


Evaluating Unsupervised Models

Evaluation is harder without labels because there is no single correct answer. Common approaches include the Silhouette Score and Davies-Bouldin Index for cluster quality, the elbow method for choosing the number of clusters in K-Means, and explained variance for PCA. In practice, results are also validated by domain experts who judge whether discovered groups are meaningful for the business.

Unsupervised Learning Example in Python

The example below generates sample data and uses K-Means to discover three clusters without any labels.

Python: clustering with K-Means

from sklearn.datasets import make_blobs

from sklearn.cluster import KMeans

 

X, _ = make_blobs(n_samples=300, centers=3, random_state=42)

 

kmeans = KMeans(n_clusters=3, n_init=10, random_state=42)

labels = kmeans.fit_predict(X)

print("First 10 cluster labels:", labels[:10])

print("Cluster centres:\n", kmeans.cluster_centers_)


Real-World Applications of Unsupervised Learning

  • Customer segmentation for targeted marketing

  • Product recommendations and market basket analysis

  • Fraud and anomaly detection in transactions and system logs

  • Topic modelling and grouping of documents

  • Data compression and visualisation of high-dimensional datasets

  • Feature extraction before training a supervised model

Advantages and Limitations

Advantages: works with abundant unlabelled data, can reveal patterns humans did not anticipate, and is valuable for exploratory analysis.

Limitations: results can be hard to interpret and evaluate, and choices such as the number of clusters or the distance metric strongly influence the outcome.

3. Reinforcement Learning

Reinforcement learning (RL) is fundamentally different from the first two types. There is no fixed dataset of correct answers. Instead, an agent learns by interacting with an environment, taking actions, and receiving rewards or penalties. Over many interactions, the agent learns a strategy that maximises its total long-term reward.

This mirrors how people and animals learn through trial and error. A child learning to ride a bicycle is not given a labelled dataset; they try, wobble, adjust, and gradually improve based on feedback.

Figure 3: The reinforcement learning loop between agent and environment

Figure 3: The reinforcement learning loop between agent and environment

Key Concepts in Reinforcement Learning

Term

Meaning

Agent

The learner or decision-maker, such as a game-playing program or a robot

Environment

Everything the agent interacts with, such as a game, a simulation, or the physical world

State (s)

A description of the current situation of the environment

Action (a)

A choice the agent can make in a given state

Reward (r)

A numerical signal indicating how good the outcome of an action was

Policy (π)

The agent's strategy that maps states to actions

Value function

The expected cumulative future reward from a state, or from a state-action pair

Discount factor (γ)

A value between 0 and 1 that controls how much future rewards matter compared with immediate ones


Most RL problems are formalised as a Markov Decision Process (MDP), in which the next state and reward depend only on the current state and action. A central challenge is the exploration versus exploitation trade-off: the agent must balance trying new actions to discover better rewards (exploration) with choosing actions already known to work well (exploitation).

Types of Reinforcement Learning Approaches

  • Value-based methods learn how good each action is in each state and choose the best one. Examples include Q-learning, SARSA, and Deep Q-Networks (DQN).

  • Policy-based methods learn the policy directly, which works well for continuous actions. Examples include REINFORCE and other policy gradient methods.

  • Actor-critic methods combine both: an actor chooses actions and a critic evaluates them. Examples include A2C, PPO (Proximal Policy Optimization), and SAC (Soft Actor-Critic).

  • Model-free vs model-based: model-free methods learn purely from experience, while model-based methods also learn or use a model of how the environment behaves in order to plan ahead.

Reinforcement Learning Example in Python

The example below uses Q-learning to teach an agent to cross the FrozenLake grid from the Gymnasium library. The agent starts with no knowledge, explores, and updates a table of action values (the Q-table) using the rewards it receives.

Python: Q-learning with Gymnasium

import numpy as np

import gymnasium as gym

 

env = gym.make("FrozenLake-v1", is_slippery=False)

Q = np.zeros((env.observation_space.n, env.action_space.n))

alpha, gamma, epsilon = 0.1, 0.99, 0.2

rng = np.random.default_rng(42)

 

for episode in range(3000):

    state, _ = env.reset(seed=int(rng.integers(1e6)))

    done = False

    while not done:

        if rng.random() < epsilon or not Q[state].any():

            action = env.action_space.sample()

        else:

            action = int(np.argmax(Q[state]))

        next_state, reward, terminated, truncated, _ = env.step(action)

        Q[state, action] += alpha * (reward + gamma * np.max(Q[next_state]) - Q[state, action])

        state, done = next_state, terminated or truncated

 

print("Learned greedy policy:", np.argmax(Q, axis=1).reshape(4, 4))


The key line is the Q-learning update. It moves the current estimate Q(s, a) towards the reward received plus the discounted value of the best action in the next state. Here, alpha is the learning rate, gamma is the discount factor, and epsilon controls how often the agent explores at random.

Real-World Applications of Reinforcement Learning

  • Games: DeepMind's DQN learned to play many Atari games from raw pixels, and AlphaGo combined deep learning with reinforcement learning to defeat Go champion Lee Sedol in 2016.

  • Robotics: teaching robots to walk, grasp objects, and perform manipulation tasks, often in simulation first.

  • Large language models: Reinforcement Learning from Human Feedback (RLHF) and related techniques are used to align chatbot responses with human preferences.

  • Recommendation and advertising: optimising long-term user engagement rather than single clicks.

  • Operations: resource scheduling, traffic signal control, and energy optimisation in data centres.

  • Finance: research into portfolio management and trade execution strategies.

Advantages and Limitations

Advantages: handles sequential decisions where actions affect future outcomes, and can discover strategies that humans had not considered.

Limitations: usually needs a very large number of interactions, can be unstable to train, and depends heavily on a well-designed reward function. A poorly designed reward can lead the agent to exploit loopholes instead of solving the intended task, a problem known as reward hacking. Real-world trial and error can also be costly or unsafe, which is why simulators are widely used.

Beyond the Big Three: Other Learning Approaches

In practice, the boundaries between types are not always strict. Two related approaches are increasingly important:

Semi-supervised learning combines a small amount of labelled data with a large amount of unlabelled data. It is useful when labelling is expensive, for example in medical imaging, where only some scans have been annotated by specialists.

Self-supervised learning creates labels automatically from the data itself. For example, a language model learns by predicting the next word in a sentence, and an image model may learn by predicting hidden parts of an image. Self-supervised pre-training is the foundation of modern large language models and many vision models, which are often fine-tuned afterwards with supervised learning and reinforcement learning.

Supervised vs Unsupervised vs Reinforcement Learning: Detailed Comparison

Criteria

Supervised

Unsupervised

Reinforcement

Input data

Labelled

Unlabelled

States from an environment

Output

Predicted label or value

Clusters, patterns, or reduced features

A policy (sequence of actions)

Feedback timing

Immediate, per example

None

Delayed, often after many actions

Evaluation

Accuracy, F1, RMSE

Silhouette score, expert review

Cumulative reward

Data cost

High (labelling)

Low

High (interactions or simulation)

Popular algorithms

Random Forest, XGBoost, SVM

K-Means, PCA, DBSCAN

Q-learning, DQN, PPO

Best for

Prediction with known outcomes

Exploration and discovery

Sequential decision-making


How to Choose the Right Type of Machine Learning

Start with the problem and the data you have, not the algorithm. These questions point to the right approach:

  • Do you have historical examples with known correct answers? Use supervised learning. Choose classification for categories and regression for numbers.

  • Do you have data but no labels, and want to understand its structure? Use unsupervised learning, such as clustering for grouping or PCA for simplifying features.

  • Does the problem involve a sequence of decisions where actions affect future outcomes? Use reinforcement learning, ideally with a simulator to train safely.

  • Do you have only a few labels but lots of raw data? Consider semi-supervised or self-supervised learning, or use a pre-trained model and fine-tune it.

Key Takeaway

Many production systems combine these types. For example, a fraud system may use unsupervised anomaly detection to flag suspicious transactions, supervised models to score risk, and human feedback to keep improving over time.

Conclusion

Summary in 30 Seconds

  • Supervised learning learns from labelled data to predict categories or values.

  • Unsupervised learning finds hidden structure in unlabelled data.

  • Reinforcement learning learns from rewards by interacting with an environment.

  • Semi-supervised and self-supervised learning bridge the gaps between these types.

  • The right choice depends on your data, your feedback signal, and your goal.


Supervised, unsupervised, and reinforcement learning are the three pillars of machine learning. Each answers a different kind of question: what will happen, what patterns exist, and what action should be taken next. Understanding how they differ in data requirements, feedback, and evaluation is the first step towards choosing the right technique for any real-world problem.

In upcoming articles on BitCodeMatrix, we will explore individual algorithms in more depth, starting with regression and classification models, and show how to build and deploy them in production.

Frequently Asked Questions

What are the three main types of machine learning? Supervised learning, unsupervised learning, and reinforcement learning. They differ in whether the model learns from labelled data, unlabelled data, or rewards from interacting with an environment.

What is the difference between supervised and unsupervised learning? Supervised learning uses labelled data to learn to predict known outputs. Unsupervised learning uses unlabelled data to discover hidden patterns or groups.

Is reinforcement learning supervised or unsupervised? Neither. It is a separate paradigm. The agent receives a reward signal rather than correct answers, and that feedback is often delayed until after several actions.

Which type of machine learning is most commonly used? Supervised learning is the most widely used in business applications because many problems involve predicting a known outcome from historical data.

Is ChatGPT trained with supervised, unsupervised, or reinforcement learning? Models like ChatGPT combine several approaches: self-supervised pre-training on large text datasets, supervised fine-tuning on example conversations, and reinforcement learning from human feedback (RLHF).

Which Python libraries are used for each type? scikit-learn covers most supervised and unsupervised algorithms; XGBoost and LightGBM are popular for gradient boosting; TensorFlow and PyTorch are used for deep learning; and Gymnasium and Stable-Baselines3 are widely used for reinforcement learning.