SLEADE#
- class capymoa.ssl.SLEADE[source]#
Bases:
MOAClassifierSSLSemi-supervised SLEADE ensemble.
SLEADE handles partially labelled data by having ensemble members teach one another: a member is trained on a pseudo-label when the rest of the ensemble predicts it with more confidence than that member would itself. Unsupervised drift detection lets the ensemble react to change without waiting for labels.
The defaults are the configuration used in the paper, so
SLEADE(schema)reproduces the published method. In particular pseudo-labels are only accepted abovessl_min_confidence, and the base ensemble runs with its own drift detection and background learner disabled, because SLEADE supplies its own unsupervised drift detection instead.Reference:
Gomes, H. M., Read, J., Grzenda, M., Pfahringer, B., & Bifet, A. (2025). SLEADE: Disagreement-Based Semi-Supervised Learning for Sparsely Labeled Evolving Data Streams. IEEE Transactions on Knowledge and Data Engineering.
>>> from capymoa.ssl import SLEADE >>> from capymoa.datasets import ElectricityTiny >>> from capymoa.evaluation import prequential_evaluation >>> >>> stream = ElectricityTiny() >>> clf = SLEADE(stream.get_schema()) >>> results = prequential_evaluation(stream, clf, max_instances=1000) >>> print(f"{results['cumulative'].accuracy():.1f}") 90.2
- __init__(
- schema: Schema,
- random_seed: int = 0,
- ensemble_size: int = 10,
- confidence_strategy: Literal['Sum', 'ArgMax'] = 'ArgMax',
- enable_random_threshold: bool = False,
- auto_weight_shrinkage: Literal['Constant', 'LabeledDivTotal', 'LabeledNoWarmupDivTotal'] = 'LabeledNoWarmupDivTotal',
- ssl_strategy: Literal['PseudoLabelAll', 'PseudoLabelCheckConfidence'] = 'PseudoLabelCheckConfidence',
- ssl_min_confidence: float = 0.9,
- weight_function: Literal['Constant1', 'Confidence', 'ConfidenceWeightShrinkage', 'UnsupervisedDetectionWeightShrinkage'] = 'ConfidenceWeightShrinkage',
- pairing_function: Literal['MinKappa', 'Random', 'MajorityTrainsMinority'] = 'MajorityTrainsMinority',
- ssl_weight_shrinkage: float = 100.0,
- use_unsupervised_drift_detection: bool = True,
- student_learner: Classifier | None = None,
- drift_detection_method: MOADriftDetector | None = None,
- unsupervised_detection_weight_window: int = 20,
- labeled_window_limit: int = 100,
Construct the SLEADE semi-supervised ensemble.
- Parameters:
schema – Stream schema.
random_seed – Random seed.
ensemble_size – Number of learners in the base ensemble. SLEADE is built on
StreamingRandomPatches, which is configured internally with its own drift detection and background learner disabled so that SLEADE’s unsupervised drift detection is what responds to change.confidence_strategy – How a prediction’s confidence is derived from the votes:
"Sum"uses the votes directly,"ArgMax"assigns 1 to the argmax of each vote array.enable_random_threshold – Draw the minimum confidence at random instead of using a fixed threshold. When set,
ssl_min_confidenceis ignored.auto_weight_shrinkage – Strategy for setting the weight shrinkage automatically.
ssl_strategy – Whether to pseudo-label everything, or only instances passing the confidence check.
ssl_min_confidence – Minimum confidence for a pseudo-label to be used for training. Ignored when
enable_random_thresholdis set.weight_function – How pseudo-labelled instances are weighted.
"UnsupervisedDetectionWeightShrinkage"only makes sense together withuse_unsupervised_drift_detection.pairing_function – How learners are paired for teaching.
ssl_weight_shrinkage – Pseudo-labelled instances are weighted by
instance weight * 1/ws.use_unsupervised_drift_detection – Whether to use the unsupervised drift detection and recovery strategy.
student_learner – Model trained to mimic the ensemble’s predictions. Because it learns from those predictions rather than from labels, its error can be tracked without any labelled data, and a change in that error is what signals drift. Only used when
use_unsupervised_drift_detectionis set. Defaults toHoeffdingTree(grace_period=50, confidence=0.01).drift_detection_method – Change detector applied to the student’s error. Defaults to
ADWIN(delta=1e-5).unsupervised_detection_weight_window – Length of the sigmoid used to weight pseudo-labelled instances after an unsupervised detection.
labeled_window_limit – Maximum number of labelled instances kept in the sliding window used to quick-start learners.
- predict(instance: Instance) int | None[source]#
Predict the label of an instance.
The base implementation calls
predict_proba()and returns the label with the highest probability.- Parameters:
instance – The instance to predict the label for.
- Returns:
The predicted label or
Noneif the classifier is unable to make a prediction.
- predict_proba(
- instance,
Return probability estimates for each label.
- Parameters:
instance – The instance to estimate the probabilities for.
- Returns:
An array of probabilities for each label or
Noneif the classifier is unable to make a prediction.
- train(instance)[source]#
Train the classifier with a labeled instance.
- Parameters:
instance – The labeled instance to train the classifier with.