Skip to content

Commit 94c3e90

Browse files
committed
remove legacy detector
1 parent 713ed19 commit 94c3e90

1 file changed

Lines changed: 0 additions & 90 deletions

File tree

src/ml3_drift/sklearn/base.py

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,13 @@
11
import numpy as np
22

3-
from collections.abc import Callable
43
from sklearn.base import BaseEstimator, TransformerMixin, check_is_fitted
5-
from abc import ABC, abstractmethod
64
from sklearn.utils.validation import validate_data
7-
from ml3_drift.callbacks.models import DriftInfo
85
from ml3_drift.enums.monitoring import DataDimension, DataType
96
from ml3_drift.monitoring.base import MonitoringAlgorithm
107

118
from copy import deepcopy
129

1310

14-
class BaseDriftDetector(TransformerMixin, BaseEstimator, ABC):
15-
"""
16-
Base class for drift detector.
17-
Base Drift Detectors are neither transformers nor predictors, they
18-
just observe the data and detects drift, executing specified
19-
actions when necessary.
20-
For this reason, they implement both the transform and predict methods.
21-
22-
Parameters
23-
----------
24-
callbacks: list[Callable[[DriftInfo], None]
25-
list of callbacks function used to act when drift are detected
26-
"""
27-
28-
def __init__(self, callbacks: list[Callable[[DriftInfo], None]] | None = None):
29-
super().__init__()
30-
self.callbacks = callbacks
31-
32-
@abstractmethod
33-
def _fit(self, X, y=None):
34-
"""
35-
Fit method that should be implemented in child classes
36-
"""
37-
38-
@abstractmethod
39-
def _detect(self, X) -> list[DriftInfo]:
40-
"""
41-
Core method for detecting drift that is implemented in child classes.
42-
"""
43-
44-
def fit(self, X, y=None):
45-
"""
46-
Fit method. Calls _inner_fit and returns self
47-
"""
48-
49-
X = self._validate_data(X, y, reset=True)
50-
self._fit(X)
51-
self.is_fitted_ = True
52-
return self
53-
54-
def transform(self, X):
55-
"""
56-
Transform method. Calls _detect method and return X.
57-
This step does not change the data but only performs drift detection.
58-
"""
59-
X = self._validate_data(X, reset=False)
60-
check_is_fitted(self)
61-
if (drift_info_list := self._detect(X)) and (self.callbacks is not None):
62-
for drift_info in drift_info_list:
63-
for callback in self.callbacks:
64-
callback(drift_info)
65-
return X
66-
67-
def predict(self, X):
68-
"""
69-
Predict method. Calls _detect method and return X.
70-
This step does not change the data but only performs drift detection.
71-
"""
72-
X = self._validate_data(X, reset=False)
73-
check_is_fitted(self)
74-
if (drift_info_list := self._detect(X)) and (self.callbacks is not None):
75-
for drift_info in drift_info_list:
76-
for callback in self._callbacks:
77-
callback(drift_info)
78-
return X
79-
80-
def _validate_data(self, X, y=None, reset=False):
81-
"""
82-
Validate data method. This calls validate_data sklearn method with
83-
provided parameters and returns the validated X.
84-
Child classes can override with their own validation methods if needed
85-
or just call the base class method with the custom parameters.
86-
"""
87-
88-
# Workaround since validate data doesn't return y if it is None
89-
if y is None:
90-
X = validate_data(self, X, reset=reset, accept_sparse=False)
91-
else:
92-
X, _ = validate_data(self, X, y, reset=reset, accept_sparse=False)
93-
return X
94-
95-
def __sklearn_tags__(self):
96-
tags = super().__sklearn_tags__()
97-
# Currently empty, but can be used to add tags to the estimator
98-
return tags
99-
100-
10111
class SklearnDriftDetector(TransformerMixin, BaseEstimator):
10212
"""Adapter class for sklearn library.
10313

0 commit comments

Comments
 (0)