Label propagation and spreading
Quick answer
Label propagation transfers known class information through a similarity graph. Label spreading also uses graph structure but softens the constraints on initially labeled nodes. Both rely on nearby observations tending to share labels. Static examples tested locally with Python 3.13.5, scikit-learn 1.8.0 SciPy 1.17.0 and NumPy 2.3.5 where imported. ByteMind package execution is unverified.
Propagate a two-class neighbor score
weights=[3,1]print([w/sum(weights) for w in weights])Observed local output:
[0.75, 0.25]This is a single normalized weighted vote, not a fully fitted graph.
How it works
Represent observations as graph nodes and similarities as weighted edges. For a simple row-normalized graph P, one propagation step multiplies P by a matrix F of class scores. Initialize labeled nodes with one-hot labels and unlabeled nodes with zeros. In hard-clamped propagation, restore the original label rows after each update. For an unlabeled node linked to class 0 with weight 3 and class 1 with weight 1, the normalized one-step score is [0.75,0.25]. Repeated updates can spread evidence along paths. LabelSpreading in scikit-learn uses a normalized graph Laplacian-based construction and soft clamping: alpha controls the contribution from neighboring scores versus the original label distribution (0 < alpha < 1). The simple row-normalized exercise is an illustration, not its exact implementation. Both estimators support RBF or nearest-neighbor kernels; gamma controls RBF locality and n_neighbors controls graph connectivity for the nearest-neighbor kernel. Disconnected components without labeled nodes cannot obtain evidence from those labels. Dense RBF graphs may require quadratic storage; nearest-neighbor graphs can reduce storage, but graph construction still has costs. Use transduction_ for fitted rows, predict for unseen rows; predictions on new rows are not the same experiment as transductive inference with those rows in the graph. Use training-only graphs and fit preprocessing only on the allowed training pool.
Compare native graph estimators
import numpy as npfrom sklearn.semi_supervised import LabelPropagation,LabelSpreadingX=np.array([[-3.],[-2.8],[-2.5],[2.5],[2.8],[3.]])y=np.array([0,-1,-1,-1,-1,1])for m in [LabelPropagation(gamma=2),LabelSpreading(gamma=2,alpha=.2)]: m.fit(X,y) print(m.transduction_.tolist(),m.predict([[-2.7],[2.7]]).tolist())Observed local output:
[0, 0, 0, 1, 1, 1] [0, 1][0, 0, 0, 1, 1, 1] [0, 1]Both methods recover the simple separated groups; agreement on this fixture is not guaranteed in general.
Common mistakes
Do not confuse a graph score with calibrated probability, assume all components contain a labeled seed, or put test features into the graph for an inductive benchmark. Soft clamping can change initial labels in the inferred distribution.
Practice and next steps
Compare an unlabeled node with edge weights (2,1) and another with (0,0). Explain why the second node needs an abstention policy rather than an arbitrary confident label. Complete the knowledge check and staged exercise. Next: Consistency learning.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Label propagation and spreading — knowledge check
Apply label propagation and spreading to new scenarios.
What does a graph edge encode?
What happens to hard-clamped original labels?
What controls soft clamping in LabelSpreading?
A component has no path to a labeled seed. What follows?
Why exclude test rows from an inductive graph?