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.
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.
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
Quick Overview of the Three Types
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
Collect labelled data: Gather examples with known outcomes, such as emails marked "spam" or "not spam".
Split the data: Divide it into training, validation, and test sets so performance can be measured on data the model has not seen.
Train the model: The algorithm learns the relationship between features and labels by minimising a loss function.
Evaluate: Measure performance on the test set using appropriate metrics.
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
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.
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
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
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.
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
Key Concepts in Reinforcement Learning
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.
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
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.
Conclusion
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.