# `STUDD`

### *class* capymoa.drift.detectors.STUDD[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/detectors/studd.py#L13)

Bases: [`BaseDriftDetector`](capymoa.drift.base_detector.BaseDriftDetector.md#capymoa.drift.base_detector.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:

```pycon
>>> 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](capymoa.base.MOAClassifier.md#capymoa.base.MOAClassifier), min_n_instances: [int](https://docs.python.org/3/builtins/functions.html#int) = 500, detector: [MOADriftDetector](capymoa.drift.base_detector.MOADriftDetector.md#capymoa.drift.base_detector.MOADriftDetector) | [None](https://docs.python.org/3/builtins/constants.html#None) = None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/detectors/studd.py#L59)

* **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](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray) | [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[float](https://docs.python.org/3/builtins/functions.html#float)] | [Instance](capymoa.core.Instance.md#capymoa.core.Instance), teacher_prediction: [int](https://docs.python.org/3/builtins/functions.html#int)) → [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/detectors/studd.py#L87)

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

* **Parameters:**
  * **instance_x** ([*Instance*](capymoa.core.Instance.md#capymoa.core.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](https://docs.python.org/3/builtins/functions.html#bool)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/base_detector.py#L52)

Is the detector currently detecting a concept drift?

#### detected_warning() → [bool](https://docs.python.org/3/builtins/functions.html#bool)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/base_detector.py#L56)

Is the detector currently warning of an upcoming concept drift?

#### *classmethod* from_params(schema: [Any](https://docs.python.org/3/library/typing.html#typing.Any) = None, params: [dict](https://docs.python.org/3/builtins/stdtypes.html#dict)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [Any](https://docs.python.org/3/library/typing.html#typing.Any)] | [None](https://docs.python.org/3/builtins/constants.html#None) = None, random_seed: [int](https://docs.python.org/3/builtins/functions.html#int) = 1) → [Any](https://docs.python.org/3/library/typing.html#typing.Any)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_learner_params.py#L170)

Construct an instance from parameters produced by `get_params`.

#### get_params() → [dict](https://docs.python.org/3/builtins/stdtypes.html#dict)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [Any](https://docs.python.org/3/library/typing.html#typing.Any)][[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/base/_learner_params.py#L163)

Return the hyper-parameters captured from the constructor.

#### instance_from_arr(x, y)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/detectors/studd.py#L127)

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](capymoa.core.LabeledInstance.md#capymoa.core.LabeledInstance)

#### reset(clean_history: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False) → [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/drift/detectors/studd.py#L140)

Reset the drift detector.

* **Parameters:**
  **clean_history** ([*bool*](https://docs.python.org/3/builtins/functions.html#bool)) – Whether to reset detection history, defaults to False

#### REQUIRES_FIT *: [bool](https://docs.python.org/3/builtins/functions.html#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()`](#capymoa.drift.detectors.STUDD.add_element).
