Skip to main content
Back to Blog
AI/MLData Analysis
4 April 20265 min readUpdated 4 April 2026

Understanding Semi-Supervised Learning in Machine Learning

Semi supervised learning is a machine learning technique that combines elements of both supervised and unsupervised learning. This method involves using a small quantity of labe...

Understanding Semi-Supervised Learning in Machine Learning

Semi-supervised learning is a machine learning technique that combines elements of both supervised and unsupervised learning. This method involves using a small quantity of labeled data alongside a larger set of unlabeled data to train models. The aim is to accurately predict outputs from inputs while minimizing the amount of labeled data required, similar to supervised learning.

What is Semi-Supervised Learning?

Semi-supervised learning is especially useful when obtaining labeled data is costly or time-consuming, yet unlabeled data is readily available and easy to gather.

  • Supervised Learning: Comparable to a student being guided by a teacher both in class and through homework.
  • Unsupervised Learning: Similar to a student learning independently without guidance, like solving a math problem.
  • Semi-Supervised Learning: A blend where the teacher provides some concepts, and the student practices through homework based on those concepts.

How Semi-Supervised Learning Works

Several techniques are commonly used in semi-supervised learning, including:

  • Self-Training: The model begins with labeled data, predicts labels for the unlabeled data, and iteratively adds high-confidence predictions to the labeled set to refine the model.
  • Co-Training: Two models are trained on different subsets of features. They label unlabeled data for each other, allowing learning from complementary perspectives.
  • Multi-View Training: A variant of co-training where models use different data representations (such as images and text) to predict the same output.
  • Graph-Based Models: Data is represented as a graph with nodes (data points) and edges (similarities), propagating labels from labeled nodes to unlabeled ones based on connectivity.

Illustration for: - Self-Training: The model beg...

Example of Semi-Supervised Learning

Step 1: Import Libraries and Load Data

import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.semi_supervised import LabelPropagation
from sklearn.metrics import accuracy_score

iris = datasets.load_iris()
X = iris.data[:, :2]
y = iris.target

Step 2: Semi-Supervised Setup (Mask Labels)

labels = np.copy(y)
rng = np.random.RandomState(42)
mask = rng.rand(len(y)) < 0.1
labels[~mask] = -1
print(f"Labeled: {np.sum(mask)}, Unlabeled: {np.sum(~mask)}")

Step 3: Train a Graph-Based Model (Label Propagation)

model = LabelPropagation()
model.fit(X, labels)

Step 4: Get Transduced Labels and Evaluate

y_pred = model.transduction_
acc_labeled = accuracy_score(y[mask], y_pred[mask])
acc_overall = accuracy_score(y, y_pred)
print(f"Acc (on original labeled subset): {acc_labeled:.3f}")
print(f"Acc (overall after propagation): {acc_overall:.3f}")

Step 5: Visualize

fig, ax = plt.subplots(1, 2, figsize=(12, 4))

ax[0].scatter(X[:, 0], X[:, 1], c='lightgray', s=30)
ax[0].scatter(X[mask, 0], X[mask, 1], c=y[mask], cmap='viridis', s=60)
ax[0].set_title("Before propagation — few labels")

ax[1].scatter(X[:, 0], X[:, 1], c=y_pred, cmap='viridis', s=60)
ax[1].set_title("After propagation — all labeled")

plt.tight_layout()
plt.show()

When to Use Semi-Supervised Learning

  • When labeled data is scarce or expensive, such as in medical imaging.
  • When large amounts of unlabeled data are available, like on social media.
  • For unstructured data types (text, images, audio) where labeling is challenging.
  • When classes are rare and labeled examples are few, enhancing class recognition.
  • When neither purely supervised nor unsupervised methods suffice.

Applications of Semi-Supervised Learning

  • Face Recognition: Improves accuracy by using graph-based methods on limited labeled images and many unlabeled ones.
  • Handwritten Text Recognition: Adapts models to various handwriting styles with generative models.
  • Speech Recognition: Enhances transcription by incorporating unlabeled speech data with CNNs.
  • Security: Used for anomaly detection in network traffic and malware detection.
  • Finance: Applied in fraud detection and credit assessment using transaction data.

Advantages

  • Better Generalization: Captures the entire data structure by using both labeled and unlabeled data, improving prediction robustness.
  • Cost Efficient: Reduces reliance on costly manual labeling by leveraging unlabeled data.
  • Flexible and Robust: Adapts to various data types and sources, managing changing data distributions.
  • Improved Clustering: Refines clusters by utilizing unlabeled data, yielding better class separation.
  • Handling Rare Classes: Enhances learning for underrepresented classes with minimal labeled examples.

Illustration for: - Better Generalization: Captu...

Limitations

  • Model Complexity: Requires careful selection of architecture and hyperparameters, necessitating extensive tuning.
  • Noisy Data: Unlabeled data may contain errors, risking degraded model performance.
  • Assumption Sensitivity: Relies on assumptions like data consistency and clusterability, which may not always hold.
  • Evaluation Challenge: Assessing performance is difficult due to limited labeled data and variable quality of unlabeled data.