Reports API¶
driftwatch.core.report.DriftReport
dataclass
¶
DriftReport(feature_results: list[FeatureDriftResult], reference_size: int, production_size: int, timestamp: datetime = (lambda: now(utc))(), model_version: str | None = None)
Comprehensive report of drift detection results.
Contains per-feature metrics and aggregate status.
Attributes:
| Name | Type | Description |
|---|---|---|
feature_results |
list[FeatureDriftResult]
|
List of per-feature drift results |
reference_size |
int
|
Number of samples in reference data |
production_size |
int
|
Number of samples in production data |
timestamp |
datetime
|
When the check was performed |
model_version |
str | None
|
Optional model version identifier |
status
property
¶
status: DriftStatus
Determine overall drift status.
Status levels are determined based on the proportion of features with detected drift:
- OK: No drift detected
- WARNING: <50% of features have drift
- CRITICAL: >=50% of features have drift
Returns:
| Type | Description |
|---|---|
DriftStatus
|
DriftStatus representing overall drift status |
Example
report.status
has_drift
¶
Check if any feature has drift.
Returns:
| Type | Description |
|---|---|
bool
|
True if at least one feature has drift, otherwise False |
Example: >>> report.has_drift() False
Source code in src/driftwatch/core/report.py
drifted_features
¶
Return list of features with detected drift.
Returns:
| Type | Description |
|---|---|
list[str]
|
list of feature name with drift. |
Example
report.drifted_features() ["age", "income"]
Source code in src/driftwatch/core/report.py
drift_ratio
¶
Return ratio of drifted features to total features.
Returns:
| Type | Description |
|---|---|
float
|
ratio (fraction) of detected drift features with total features. |
Example
report.drift_ratio() 0.25
Source code in src/driftwatch/core/report.py
feature_drift
¶
feature_drift(feature_name: str) -> FeatureDriftResult | None
Get drift result for a specific feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_name
|
str
|
name of the feature to get drift result. |
required |
Returns:
| Type | Description |
|---|---|
FeatureDriftResult | None
|
FeatureDriftResult if the feature exists otherwise None. |
Example
result=report.feature_drift("age") result.has_drift True
Source code in src/driftwatch/core/report.py
summary
¶
Generate a human-readable summary of the drift report.
Returns:
| Type | Description |
|---|---|
str
|
Formatted string summary |
Example
print(report.summary()) DRIFT REPORT
Source code in src/driftwatch/core/report.py
to_dict
¶
Convert report to dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary representation of the drift report. |
Example
report.to_dict()["status"] 'OK'
Source code in src/driftwatch/core/report.py
to_json
¶
Convert report to JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
int
|
number of spaces used for JSON indentation. |
2
|
Returns:
| Type | Description |
|---|---|
str
|
JSON-formatted string. |
Example
json_str = report.to_json() '"status"' in json_str True
Source code in src/driftwatch/core/report.py
driftwatch.core.report.FeatureDriftResult
dataclass
¶
FeatureDriftResult(feature_name: str, has_drift: bool, score: float, method: str, threshold: float, p_value: float | None = None, drift_type: DriftType = FEATURE)
Result of drift detection for a single feature.
Attributes:
| Name | Type | Description |
|---|---|---|
feature_name |
str
|
name of feature. |
has_drift |
bool
|
whether drift was detected. |
score |
float
|
drift score as produced by detector. |
method |
str
|
name of detection method used. |
threshold |
float
|
threshold value used for detection. |
p_value |
float | None
|
optional p_value associated with test. |
Example
result = FeatureDriftResult( ... feature_name = "age", ... has_drift = True, ... score = 0.32, ... method = "psi", ... threshold = 0.2, ... ) result.to_dict()["has_drift"] True
to_dict
¶
Convert to dictionary.
Source code in src/driftwatch/core/report.py
driftwatch.core.report.DriftStatus
¶
Bases: str, Enum
Overall drift status levels.