Semi-supervised learning trains a model on a small set of labeled examples plus a much larger set of unlabeled ones. In Python, the quickest route is scikit-learn's sklearn.semi_supervised module: mark unlabeled samples with -1 in the label array, then fit SelfTrainingClassifier, LabelPropagation or LabelSpreading. For neural networks, pseudo-labeling and consistency regularization in PyTorch or Keras follow the same idea.
It pays off when labeling is expensive, such as medical images, support tickets or audio transcripts, and raw data is cheap. The method only helps when the unlabeled data comes from the same distribution as the labeled data.
Supervised learning needs a label for every training row. Unsupervised learning uses no labels at all. Semi-supervised learning sits between them: the labeled rows define the task, and the unlabeled rows reveal the shape of the data, such as clusters and low-density gaps between classes.
| Approach | Labels needed | Typical goal |
|---|---|---|
| Supervised | All rows | Predict a label |
| Unsupervised | None | Find structure |
| Semi-supervised | A few rows | Predict a label using extra unlabeled data |
Most methods rely on one of two assumptions. The cluster assumption says points in the same cluster share a label. The smoothness assumption says nearby points have similar labels. If your data breaks these assumptions, unlabeled data can hurt accuracy instead of helping.
scikit-learn uses the label -1 to mean "unlabeled". The example below keeps 10% of the labels from the digits dataset and hides the rest.
Always split off the test set before hiding labels, and evaluate on test rows whose true labels were never used in training.
SelfTrainingClassifier wraps any classifier that implements predict_proba. It trains on the labeled rows, predicts the unlabeled rows, adds the predictions it is confident about as pseudo-labels, and repeats.
The threshold controls how confident a prediction must be before it becomes a pseudo-label. A high value is safer but adds fewer samples; a low value adds more noise. Compare against a baseline trained only on the labeled rows to confirm that the unlabeled data actually helps.
LabelPropagation and LabelSpreading build a similarity graph over all rows and spread labels along its edges. LabelSpreading uses a normalized graph and a clamping factor alpha, which makes it more robust to noisy labels.
The transduction_ attribute holds the label assigned to every training row, including the unlabeled ones. Graph methods store an n by n structure, so they suit small and medium datasets. The kernel="knn" option keeps the graph sparse and scales better than rbf.
For deep learning, a common recipe is to train on labeled data, predict the unlabeled data, keep confident predictions and retrain. This sketch uses Keras 3 with a small dense network.
Newer methods such as FixMatch and Mean Teacher add data augmentation and consistency losses on top of pseudo-labels, but they follow the same pattern. They are usually implemented in PyTorch with custom training loops.
Pipeline.There is no fixed number. You need enough labeled examples per class for the base model to be better than random on its own, often tens per class for simple problems and more for complex ones.
Start with SelfTrainingClassifier and a probabilistic model, because it works with any compatible classifier and scales well. Try LabelSpreading for small datasets with a meaningful distance metric.
Yes. If the unlabeled data is from a different distribution or the pseudo-labels are noisy, the model can get worse than a supervised baseline. Always compare against one.
No. Transfer learning reuses a model trained on another task. Semi-supervised learning uses unlabeled data from the same task. You can combine them.
Mark unlabeled rows with -1, then use SelfTrainingClassifier for a general approach or LabelSpreading for graph-based labeling on smaller data. For deep networks, use confident pseudo-labels or consistency methods. Hold out a clean test set, compare against a labeled-only baseline and watch for noisy pseudo-labels.