Implementation:Evidentlyai Evidently Legacy Target Drift Preset
| Knowledge Sources | |
|---|---|
| Domains | ML Monitoring, Data Drift |
| Last Updated | 2026-02-14 12:00 GMT |
Overview
TargetDriftPreset is a metric preset that assembles a set of drift detection and correlation metrics for target and prediction columns, adapting its behavior based on task type (regression vs classification).
Description
The TargetDriftPreset class extends MetricPreset and dynamically generates a list of metrics based on the data definition (target column, prediction columns, and task type). The generated metrics include:
- ColumnDriftMetric -- applied to target and prediction columns (including prediction probability columns for classification) to detect statistical drift
- ColumnValuePlot -- added for the target column only when the task is regression
- ColumnCorrelationsMetric -- added for both target and prediction columns to show correlations
- TargetByFeaturesTable -- added when target or prediction columns are present
The preset supports extensive customization of statistical tests and thresholds:
- A global
stattestandstattest_threshold - Type-specific overrides:
cat_stattest,num_stattest,text_stattest(and corresponding thresholds) - Per-column overrides:
per_column_stattestandper_column_stattest_threshold
Statistical test resolution is handled by resolve_stattest_threshold, which determines the appropriate test and threshold for each column based on its type (categorical or numerical, determined by the task type).
The class is registered with the type alias "evidently:metric_preset:TargetDriftPreset".
Usage
Use this preset when you need to monitor target and prediction drift between a reference and current dataset. It is particularly useful for model monitoring pipelines where you want to detect distribution shifts in the target variable and model predictions over time.
Code Reference
Source Location
- Repository: Evidentlyai_Evidently
- File:
src/evidently/legacy/metric_preset/target_drift.py
Signature
class TargetDriftPreset(MetricPreset):
class Config:
type_alias = "evidently:metric_preset:TargetDriftPreset"
columns: Optional[List[str]]
stattest: Optional[PossibleStatTestType]
cat_stattest: Optional[PossibleStatTestType]
num_stattest: Optional[PossibleStatTestType]
text_stattest: Optional[PossibleStatTestType]
per_column_stattest: Optional[Dict[str, PossibleStatTestType]]
stattest_threshold: Optional[float]
cat_stattest_threshold: Optional[float]
num_stattest_threshold: Optional[float]
text_stattest_threshold: Optional[float]
per_column_stattest_threshold: Optional[Dict[str, float]]
def __init__(
self,
columns: Optional[List[str]] = None,
stattest: Optional[PossibleStatTestType] = None,
cat_stattest: Optional[PossibleStatTestType] = None,
num_stattest: Optional[PossibleStatTestType] = None,
text_stattest: Optional[PossibleStatTestType] = None,
per_column_stattest: Optional[Dict[str, PossibleStatTestType]] = None,
stattest_threshold: Optional[float] = None,
cat_stattest_threshold: Optional[float] = None,
num_stattest_threshold: Optional[float] = None,
text_stattest_threshold: Optional[float] = None,
per_column_stattest_threshold: Optional[Dict[str, float]] = None,
):
...
def generate_metrics(
self, data_definition: DataDefinition, additional_data: Optional[Dict[str, Any]]
) -> List[AnyMetric]:
...
Import
from evidently.legacy.metric_preset.target_drift import TargetDriftPreset
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| columns | Optional[List[str]] |
No | List of column names (currently stored but not directly used in metric generation). |
| stattest | Optional[PossibleStatTestType] |
No | Default statistical test to use for drift detection. |
| cat_stattest | Optional[PossibleStatTestType] |
No | Statistical test override for categorical columns. |
| num_stattest | Optional[PossibleStatTestType] |
No | Statistical test override for numerical columns. |
| text_stattest | Optional[PossibleStatTestType] |
No | Statistical test override for text columns. |
| per_column_stattest | Optional[Dict[str, PossibleStatTestType]] |
No | Per-column statistical test overrides. |
| stattest_threshold | Optional[float] |
No | Default threshold for the statistical test. |
| cat_stattest_threshold | Optional[float] |
No | Threshold override for categorical columns. |
| num_stattest_threshold | Optional[float] |
No | Threshold override for numerical columns. |
| text_stattest_threshold | Optional[float] |
No | Threshold override for text columns. |
| per_column_stattest_threshold | Optional[Dict[str, float]] |
No | Per-column threshold overrides. |
Outputs
| Name | Type | Description |
|---|---|---|
| return | List[AnyMetric] |
A dynamically generated list of metrics including ColumnDriftMetric, ColumnValuePlot (regression only), ColumnCorrelationsMetric, and TargetByFeaturesTable based on the data definition. |
Usage Examples
from evidently.legacy.metric_preset.target_drift import TargetDriftPreset
from evidently.legacy.report import Report
# Basic target drift analysis with default settings
report = Report(metrics=[TargetDriftPreset()])
report.run(reference_data=ref_df, current_data=curr_df)
# Target drift with custom statistical test and threshold
report = Report(metrics=[
TargetDriftPreset(
stattest="ks",
stattest_threshold=0.05,
cat_stattest="chi2",
cat_stattest_threshold=0.01,
)
])
report.run(reference_data=ref_df, current_data=curr_df)
# Target drift with per-column test overrides
report = Report(metrics=[
TargetDriftPreset(
per_column_stattest={"target": "wasserstein"},
per_column_stattest_threshold={"target": 0.1},
)
])
report.run(reference_data=ref_df, current_data=curr_df)