ChiSquareTest#

class frouros.detectors.data_drift.batch.statistical_test.ChiSquareTest(callbacks: BaseCallbackBatch | list[BaseCallbackBatch] | None = None)#

ChiSquareTest (Chi-square test) [pearson1900x] detector.

Parameters:

callbacks (Optional[Union[BaseCallbackBatch, list[BaseCallbackBatch]]]) – callbacks, defaults to None

Note:

References:

[pearson1900x]

Pearson, Karl. “X. On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling.” The London, Edinburgh, and Dublin Philosophical Magazine and Journal of Science 50.302 (1900): 157-175.

Example:

>>> from frouros.detectors.data_drift import ChiSquareTest
>>> import numpy as np
>>> np.random.seed(seed=31)
>>> X = np.random.choice(a=[0, 1], size=100, p=[0.5, 0.5])
>>> Y = np.random.choice(a=[0, 1], size=100, p=[0.8, 0.2])
>>> detector = ChiSquareTest()
>>> _ = detector.fit(X=X)
>>> detector.compare(X=Y)[0]
StatisticalResult(statistic=9.81474665685192, p_value=0.0017311812135839511)
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_type: BaseStatisticalType#

Statistical type property.

Returns:

statistical type

Return type:

BaseStatisticalType