Semi-Supervised Label Propagation

medium
Unit 16 · Semi Supervised0/3 to milestone

You have 1,000 examples but only 10 labels. Label propagation spreads the known labels along a similarity graph, so unlabelled points take the label of the region they sit in.

Implement label_propagation(X, labels, gamma=1.0, iters=1000, tol=1e-6), where labels uses -1 for unlabelled points and 0..K-1 otherwise:

  1. Build RBF affinities Wij=exp⁡(−γ∥xi−xj∥2)W_{ij} = \exp(-\gamma\lVert x_i - x_j\rVert^2) with a zero diagonal, and the row-normalised transition matrix T=D−1WT = D^{-1}W.
  2. Start F with one-hot rows for labelled points and zeros for the rest.
  3. Repeat F = T @ F, then clamp the labelled rows back to their one-hot values, until the largest change is below tol or iters is reached.
  4. Return (predicted_labels, F), where predictions are the row argmax.
#semi-supervised#graphs#classification2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Semi-Supervised Label Propagation · TechGradify