- Introduced by
- Zhu, X. & Ghahramani, Z. (label propagation); Cover, T. & Hart, P. (KNN base)
- Year
- 2002 (semi-supervised extension); 1967 (KNN base)
- Type
- Semi-supervised classifier / label propagation
- Family
- Machine learning
What does it do?
Semi-supervised KNN extends the classic K-nearest neighbors approach to use a large pool of unlabeled observations together with a small labeled set.
It builds a KNN graph over all observations and spreads known labels along the graph's edges, so unlabeled points receive predicted labels without every sample being annotated by hand.
The intuition behind the method
Consider a room where only a few people wear name tags. A standard KNN classifier can label an untagged person only from the tagged people among their nearest neighbors. The semi-supervised version links every person to their nearest neighbors, forming a network over the whole room, and lets labels travel outward from the tagged people along those links. Stronger links carry labels more readily, and weaker links pass them on more slowly. Because unlabeled points are part of the network, they influence how labels move, so the method uses the unlabeled majority rather than ignoring it.
History
Zhu and Ghahramani (2002) introduced label propagation on graphs for learning from labeled and unlabeled data, in a technical report from Carnegie Mellon University. The update written in this page's formula is one formulation of graph label diffusion and is not claimed to reproduce the 2002 report's algorithm exactly. The K-nearest neighbor base classifier dates from Cover and Hart (1967). The edited volume Semi-Supervised Learning by Chapelle, Scholkopf and Zien (2006) collects work on this family of methods. Approximate nearest-neighbor libraries such as FAISS and Annoy later made graph construction feasible on larger datasets.
When to use it
Use semi-supervised KNN when you have a small labeled set and a large unlabeled pool from the same distribution, the data lives in a relatively low-dimensional feature space, and you believe neighboring points share the same class. The method rests on three assumptions: the smoothness assumption (nearby points tend to have the same label), the cluster assumption (points in the same dense region tend to share a class, so class boundaries fall in low-density gaps), and a shared distribution for labeled and unlabeled data. It also depends on the distance measure: Euclidean distance on standardized features must be a reasonable proxy for similarity in the problem. It is well suited to image patch classification, text categorization with sparse annotations, and medical screening tasks where expert labeling is expensive. Avoid it when labeled and unlabeled data come from different distributions (covariate shift), the feature space is very high-dimensional (the KNN graph becomes unreliable), the dataset is small enough that fully supervised KNN already suffices, or the class boundaries do not align with the local density structure of the data.
Limitations and considerations
- Exact graph construction compares every pair of points, so cost grows quadratically with the number of observations unless approximate neighbor search is used.
- Distance-based neighborhoods become less informative in high-dimensional feature spaces, so the graph can link points that are not similar. For this reason the method is best applied to lower-dimensional features, and graph quality should be checked on validation data rather than assumed from the number of features.
- All observations, labeled and unlabeled, shape the graph. If unlabeled points come from a different distribution, they join neighborhoods and carry labels into regions where they do not belong.
- Three interacting settings (k, the bandwidth sigma, and alpha) control the result, and the method does not select them automatically.
- Errors in the labeled seeds spread through the graph along the same edges that carry correct labels, and nothing in the update identifies which seeds are wrong.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Unlabeled observations contribute through the graph's edges, so a small labeled set can be extended to many points without fitting a parametric model.
- The score matrix has one column per class and each prediction is an argmax over those columns, so multi-class problems need no one-vs-rest decomposition.
- The graph is an explicit object: its neighbor lists and edge weights can be inspected to see which points lie close to a given prediction and how strongly they are linked.
- It performs best where classes form locally dense groups, because same-class points are then linked by strong edges and labels travel mainly within a class.
Applications
- Image classification with a small set of labeled images and a large unlabeled corpus.
- Text and document categorization where manual labeling is expensive.
- Medical record or pathology slide classification with limited expert annotations.
- Fraud detection when only a small number of confirmed fraud cases are available.
- Sensor data labeling in industrial IoT settings with sparse ground-truth events.
How it works
How it works
A graph is built over all observations, both labeled and unlabeled. Each node corresponds to one data point, and directed or undirected edges connect each node to its k nearest neighbors in the feature space. The choice of k controls how locally or globally labels will be propagated: small k keeps propagation tight; large k allows labels to jump across larger gaps.
Edge weights capture the strength of similarity between connected nodes, typically via a Gaussian (RBF) kernel applied to the Euclidean distance between feature vectors. A bandwidth parameter sigma controls how quickly similarity decays with distance. Stronger edges carry labels more readily during propagation.
Formula
w_{ij} = \exp(-\|x_i - x_j\|^2 / \sigma^2)Each iteration updates the score matrix F as alpha times W D^-1 F plus (1 - alpha) times Y. The first term passes scores from each node's neighbors, weighted by edge strength and scaled by the inverse of node degree in D. The second term re-injects the initial label matrix Y, so scores remain anchored to the observed labels. Alpha sets the balance: a larger alpha gives the graph more influence, and a smaller alpha keeps scores closer to the initial labels. The normalization W D^-1 is not symmetric; a symmetric normalization, D^-1/2 W D^-1/2, is a common alternative and can lead to different scores. The update written here is one formulation of graph-based label diffusion and is not presented as the exact algorithm of the 2002 report. Iteration stops when F no longer changes appreciably.
Formula
F \leftarrow \alpha W D^{-1} F + (1-\alpha) YAfter propagation stops, each unlabeled node is assigned the class with the largest entry in its row of F. Labeled nodes are softly anchored in this formulation: the update mixes Y into every row with weight (1 - alpha) rather than holding labeled nodes fixed at their known labels. A labeled node is therefore pulled toward its given label, but strong neighbor evidence can make its final argmax differ from that label. Implementations that clamp labeled nodes to their known labels follow a different convention and can produce different predictions, so check which convention your software uses.
Formula
\hat{y}_i = \arg\max_c F_{ic}Common pitfalls
- Building the RBF weights on raw features: variables with large scales dominate the Euclidean distance and therefore the edge weights, so features are usually standardized first.
- Choosing k too large, which lets labels cross true class boundaries and produces flat score distributions across classes.
- Evaluating on nodes that took part in graph construction. Test points whose labels were hidden but which were included as unlabeled nodes can give optimistic accuracy compared with genuinely new points, because their own neighborhoods shaped the graph. Report which evaluation setting was used and treat any gap between the two settings as part of the result.
- Stopping at a fixed iteration count without checking that F has stopped changing, so predictions reflect an unfinished diffusion.
- Comparing alpha values across implementations: alpha here is defined as in the mechanics formula, and other libraries may use the mixing parameter with a different convention.
Frequently asked questions
How do I choose k?
Choose k by tuning on held-out labeled validation accuracy. Smaller k keeps propagation local and gives sharper boundaries; larger k lets labels reach further but increases the risk that they cross true class boundaries.
Can I evaluate the method honestly when most data are unlabeled?
Hold out a labeled test set and keep its labels hidden from propagation, so that no test label enters the label matrix Y. Because the method is transductive, held-out points are scored only if they are part of the graph: they can be added as unlabeled nodes before propagation, which gives transductive accuracy that can be optimistic for genuinely new points. This formulation has no separate rule for scoring unseen points. For a new point, add it as an unlabeled node, rebuild the graph, re-run propagation, and report that setting explicitly.
What if my dataset is too large to build a full KNN graph?
Use approximate nearest-neighbor libraries such as FAISS or Annoy, which avoid comparing every pair of points, and then run label propagation on the sparse approximate graph. Approximation changes which edges exist, so where feasible check results against an exact graph on a subset.
Does semi-supervised KNN always outperform supervised KNN?
Not necessarily. If unlabeled data are out-of-distribution or the feature space is very high-dimensional, the graph is noisy and propagation can hurt performance. Always compare against a supervised KNN baseline before claiming a benefit from unlabeled data.
Is this the same as label spreading or label propagation in scikit-learn?
Closely related. Scikit-learn provides LabelPropagation and LabelSpreading, which implement related graph-based label diffusion. Their parameter conventions and graph normalization differ from the formulation on this page, so check their documentation before transferring alpha or other settings.
How should I read the output scores?
The rows of F are scores for each class, not calibrated probabilities, and they are not guaranteed to sum to one. Use the predicted class as the argmax, and treat the gap between the largest and second-largest entry in a row as a rough indicator of confidence: a small gap means the neighborhood evidence is mixed and the prediction is less reliable. If probabilities are needed, calibrate the scores on validation data before using them as such.
Related methods
Sources
Zhu, X. & Ghahramani, Z. (2002). Learning from labeled and unlabeled data with label propagation. Technical Report CMU-CALD-02-107, Carnegie Mellon University.
Open publication referenceChapelle, O., Scholkopf, B. & Zien, A. (Eds.) (2006). Semi-Supervised Learning. MIT Press.
ISBN: 978-0-262-03358-9