alibi-detect
alibi-detect copied to clipboard
Add a drift detector base class
We should explore adding a base drift detector class. This could help with a number of issues:
-
The
preprocess
methods are heavily duplicated across drift detectors (incd.base
):if self.preprocess_fn is not None: x = self.preprocess_fn(x) if not self.preprocess_at_init and not self.x_ref_preprocessed: x_ref = self.preprocess_fn(self.x_ref) else: x_ref = self.x_ref return x_ref, x # type: ignore[return-value] else: return self.x_ref, x # type: ignore[return-value]
-
The preprocess logic in detector
__init__
methods is heavily duplicated:# x_ref preprocessing self.preprocess_at_init = preprocess_at_init self.x_ref_preprocessed = x_ref_preprocessed if preprocess_fn is not None and not isinstance(preprocess_fn, Callable): # type: ignore[arg-type] raise ValueError("`preprocess_fn` is not a valid Callable.") if self.preprocess_at_init and not self.x_ref_preprocessed and preprocess_fn is not None: self.x_ref = preprocess_fn(x_ref) else: self.x_ref = x_ref
-
Some args/kwargs and methods are shared by all drift detectors i.e.
input_shape
anddata_type
. A base class would ensure these are included in new drift detectors (similar to an abstract method).
We should also check the super().__init__()
calls in classes like MMDDrift
. Some may not be neccesary.