STUDD#

class capymoa.drift.detectors.STUDD[source]#

Bases: BaseDriftDetector

STUDD: Student-Teacher Unsupervised Drift Detection

STUDD is a concept drift detection method that uses a student-teacher approach. It trains a student model to mimic a teacher model’s predictions and monitors the agreement between them to detect concept drift in an unsupervised manner.

The detector works by: 1. Training a student model on the same data as the teacher 2. Monitoring the agreement between student and teacher predictions 3. Using a base drift detector (e.g., ADWIN) on the agreement signal

Example usage:

>>> from capymoa.drift.detectors import ADWIN
>>> from capymoa.drift.detectors import STUDD
>>> from capymoa.classifier import AdaptiveRandomForestClassifier as ARF
>>> from capymoa.datasets import ElectricityTiny
>>>
>>> stream = ElectricityTiny()
>>>
>>> learner = ARF(schema=stream.get_schema())
>>> student = ARF(schema=stream.get_schema())
>>>
>>> detector = STUDD(student=student, detector=ADWIN())
>>>
>>> instances_processed = 0
>>> while stream.has_more_instances():
...     instance = stream.next_instance()
...
...     prediction = learner.predict(instance)
...     detector.add_element(instance, prediction)
...
...     if detector.detected_change():
...         print(f'Change detected at index: {instances_processed}')
...
...     instances_processed += 1

Reference:

Cerqueira, V., Gomes, H. M., Bifet, A., & Torgo, L. (2023). STUDD: A student–teacher method for unsupervised concept drift detection. Machine Learning, 112(11), 4351-4378.

__init__(
student: MOAClassifier,
min_n_instances: int = 500,
detector: MOADriftDetector | None = None,
)[source]#
Parameters:
  • student – Student model that mimics the teacher’s predictions

  • min_n_instances – Minimum number of instances before monitoring drift

  • detector – Base drift detector to monitor agreement signal

add_element(
instance_x: ndarray | list[float] | Instance,
teacher_prediction: int,
) → None[source]#

Update the drift detector with a new instance and teacher prediction.

Parameters:
  • instance_x (Instance) – The instance to add to the drift detector.

  • teacher_prediction (Any) – The prediction made by the teacher model for this instance.

detected_change() → bool[source]#

Is the detector currently detecting a concept drift?

detected_warning() → bool[source]#

Is the detector currently warning of an upcoming concept drift?

classmethod from_params(
schema: Any = None,
params: dict[str, Any] | None = None,
random_seed: int = 1,
) → Any[source]#

Construct an instance from parameters produced by get_params.

get_params() → dict[str, Any][source]#

Return the hyper-parameters captured from the constructor.

instance_from_arr(x, y)[source]#

Convert an instance and prediction to a LabeledInstance.

Parameters:
  • x (Any) – The instance to convert.

  • y (Any) – The prediction made by the teacher model for this instance.

Returns:

The converted LabeledInstance.

Return type:

LabeledInstance

reset(clean_history: bool = False) → None[source]#

Reset the drift detector.

Parameters:

clean_history (bool) – Whether to reset detection history, defaults to False

REQUIRES_FIT: bool = False#

If True, this detector needs a reference distribution before it can detect change. Concept drift detectors leave this as False and only use add_element().