MMD#
- class frouros.detectors.data_drift.batch.distance_based.MMD(kernel: ~typing.Callable = <function rbf_kernel>, chunk_size: int | None = None, callbacks: ~frouros.callbacks.batch.base.BaseCallbackBatch | list[~frouros.callbacks.batch.base.BaseCallbackBatch] | None = None)#
MMD (Maximum Mean Discrepancy) [gretton2012kernel] detector.
- Parameters:
kernel (Callable) – kernel function, defaults to
rbf_kernel()
chunk_size (Optional[int]) – chunk size value, defaults to None
callbacks (Optional[Union[BaseCallbackBatch, list[BaseCallbackBatch]]]) – callbacks, defaults to None
- References:
[gretton2012kernel]Gretton, Arthur, et al. “A kernel two-sample test.” The Journal of Machine Learning Research 13.1 (2012): 723-773.
- Example:
>>> from functools import partial >>> from frouros.detectors.data_drift import MMD >>> from frouros.utils.kernels import rbf_kernel >>> import numpy as np >>> np.random.seed(seed=31) >>> X = np.random.multivariate_normal(mean=[1, 1], cov=[[2, 0], [0, 2]], size=100) >>> Y = np.random.multivariate_normal(mean=[0, 0], cov=[[2, 1], [1, 2]], size=100) >>> detector = MMD(kernel=partial(rbf_kernel, sigma=0.5)) >>> _ = detector.fit(X=X) >>> detector.compare(X=Y)[0] DistanceResult(distance=0.02146955300299802)
- property chunk_size: int | None#
Chunk size property.
- Returns:
chunk size to use
- Return type:
int
- property kernel: Callable#
Kernel property.
- Returns:
kernel function to use
- Return type:
Callable
- property X_ref: ndarray | None#
Reference data property.
- Returns:
reference data
- Return type:
Optional[numpy.ndarray]
- property callbacks: list[BaseCallback] | None#
Callbacks property.
- Returns:
callbacks
- Return type:
Optional[list[BaseCallback]]
- compare(X: ndarray, **kwargs: Any) Tuple[ndarray, dict[str, Any]] #
Compare values.
- Parameters:
X (numpy.ndarray) – test data
- Returns:
compare result and callbacks logs
- Return type:
Tuple[numpy.ndarray, dict[str, Any]]
- property data_type: BaseDataType#
Data type property.
- Returns:
data type
- Return type:
BaseDataType
- fit(X: ndarray, **kwargs: Any) dict[str, Any] #
Fit detector.
- Parameters:
X (numpy.ndarray) – feature data
kwargs (Any) – additional fit parameters
- Returns:
callbacks logs
- Return type:
dict[str, Any]
- reset() None #
Reset method.
- property statistical_kwargs: dict[str, Any]#
Statistical kwargs property.
- Returns:
statistical kwargs
- Return type:
dict[str, Any]
- property statistical_method: Callable#
Statistical method property.
- Returns:
statistical method
- Return type:
Callable
- property statistical_type: BaseStatisticalType#
Statistical type property.
- Returns:
statistical type
- Return type:
BaseStatisticalType