Detectors API¶
driftwatch.detectors.base.BaseDetector
¶
Bases: ABC
Abstract base class for drift detectors.
All drift detection methods should inherit from this class
and implement the detect method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
Threshold value for determining drift |
required |
name
|
str
|
Human-readable name for the detector |
required |
Source code in src/driftwatch/detectors/base.py
detect
abstractmethod
¶
Detect drift between reference and production data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference
|
Series
|
Reference data series |
required |
production
|
Series
|
Production data series |
required |
Returns:
| Type | Description |
|---|---|
DetectionResult
|
DetectionResult with drift status and metrics |
Source code in src/driftwatch/detectors/base.py
driftwatch.detectors.numerical.PSIDetector
¶
Bases: BaseDetector
Population Stability Index (PSI) for numerical drift detection.
PSI measures the shift in distribution between two populations. Commonly used thresholds: - PSI < 0.1: No significant change - 0.1 <= PSI < 0.2: Minor shift - PSI >= 0.2: Significant shift (drift)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
PSI value above which drift is detected. Default is 0.2. |
0.2
|
buckets
|
int
|
Number of buckets for binning. Default is 10. |
10
|
Example
detector = PSIDetector(threshold=0.2, buckets=10) result = detector.detect(reference_series, production_series)
Source code in src/driftwatch/detectors/numerical.py
detect
¶
Calculate PSI between reference and production distributions.
Returns:
| Type | Description |
|---|---|
DetectionResult
|
DetectionResult with PSI score |
Source code in src/driftwatch/detectors/numerical.py
driftwatch.detectors.numerical.KSDetector
¶
Bases: BaseDetector
Kolmogorov-Smirnov test for numerical drift detection.
The KS test measures the maximum distance between the cumulative distribution functions of two samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
P-value threshold below which drift is detected. Default is 0.05 (95% confidence). |
0.05
|
Example
detector = KSDetector(threshold=0.05) result = detector.detect(reference_series, production_series) print(f"Drift detected: {result.has_drift}")
Source code in src/driftwatch/detectors/numerical.py
detect
¶
Perform KS test between reference and production distributions.
Returns:
| Type | Description |
|---|---|
DetectionResult
|
DetectionResult with KS statistic as score and p-value |
Source code in src/driftwatch/detectors/numerical.py
driftwatch.detectors.numerical.WassersteinDetector
¶
Bases: BaseDetector
Wasserstein distance (Earth Mover's Distance) for drift detection.
Measures the minimum "work" required to transform one distribution into another. More sensitive to subtle distributional changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
Distance above which drift is detected. |
0.1
|
Source code in src/driftwatch/detectors/numerical.py
detect
¶
Calculate Wasserstein distance between distributions.
Note: Values are normalized by the reference standard deviation to make the threshold more interpretable.
Source code in src/driftwatch/detectors/numerical.py
driftwatch.detectors.categorical.ChiSquaredDetector
¶
Bases: BaseDetector
Chi-Squared test for categorical drift detection.
Tests whether the frequency distribution of categories has changed between reference and production data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
P-value threshold below which drift is detected. Default is 0.05 (95% confidence). |
0.05
|
Example
detector = ChiSquaredDetector(threshold=0.05) result = detector.detect(reference_series, production_series)
Source code in src/driftwatch/detectors/categorical.py
detect
¶
Perform Chi-Squared test on category frequencies.
Returns:
| Type | Description |
|---|---|
DetectionResult
|
DetectionResult with chi-squared statistic and p-value |