Description
Semi-supervised learning addresses situations where training datasets contain a mix of labeled and unlabeled samples. Scikit-learn's `sklearn.semi_supervised` module provides estimators designed to utilize this unlabeled data, thereby better understanding the data distribution and improving generalization to new, unseen samples. These techniques are particularly effective when labeled data is scarce, but unlabeled data is plentiful.
It's important to note that semi-supervised algorithms rely on assumptions about the data distribution to achieve performance gains. The module offers two primary approaches: Self Training and Label Propagation.
Self Training, based on Yarowsky’s algorithm, allows any supervised classifier that supports `predict_proba` to function in a semi-supervised manner. The `SelfTrainingClassifier` iteratively predicts labels for unlabeled samples and adds a subset of these to the labeled dataset. The selection of these samples can be based on prediction probabilities, using a threshold or selecting the k-best samples. This process continues until all samples are labeled or no new samples are selected in an iteration, with the maximum number of iterations controllable via `max_iter`.
Label Propagation encompasses several semi-supervised graph inference algorithms, including `LabelPropagation` and `LabelSpreading`. These models construct a similarity graph across all input data points. The core idea is that the structure of unlabeled data is consistent with class structures, allowing class labels to propagate to unlabeled observations. `LabelPropagation` performs hard clamping of input labels, while `LabelSpreading` offers a more robust approach by minimizing a loss function with regularization properties, making it more resilient to noise. Both models support built-in kernel methods like RBF and KNN, influencing scalability and performance. The RBF kernel creates a dense graph, potentially memory-intensive, whereas the KNN kernel generates a sparse graph, offering better memory efficiency and reduced running times.
These methods are valuable for tasks where manual labeling is costly or time-consuming, enabling the creation of more robust and accurate models by harnessing the wealth of available unlabeled data. The choice between Self Training and Label Propagation depends on the specific dataset characteristics and the desired approach to leveraging unlabeled information.
Scikit-learn Semi-supervised Learning Highlights
Supports semi-supervised classification
Utilizes unlabeled data for improved generalization
Includes Self Training algorithm
Supports Label Propagation and Label Spreading
Constructs similarity graphs for label propagation
Offers RBF and KNN kernel methods
Allows control over label clamping in propagation
Iterative learning process for Self Training
Adaptable to various supervised classifiers for Self Training
Handles scenarios with limited labeled data
Enhances understanding of underlying data distribution
Getting Started with Scikit-learn Semi-supervised Learning
Access model: Import relevant estimators from `sklearn.semi_supervised`.
Prepare data: Organize labeled and unlabeled samples.
Configure estimator: Instantiate `SelfTrainingClassifier` or `LabelPropagation`/`LabelSpreading` with desired parameters.
Train model: Fit the chosen estimator to the prepared dataset.
Predict labels: Use the trained model to predict labels for new data.
Evaluate performance: Assess model accuracy and generalization capabilities.
Scikit-learn Semi-supervised Learning's Use Cases
- Text Classification
- Image Recognition
- Fraud Detection
- Customer Segmentation
- Medical Diagnosis
- Speech Recognition




