skip to content

In Evidently 0.7, how does DataDriftPreset pick each column's drift method, and how do you pin one so it stops depending on reference size?

level: middleimportance: should knowfreq 9%

answer

  1. column type and reference row count
  2. a switch at 1,000 rows
  3. p-values below, distances above
  4. few unique values count as categorical
  5. per-column beats type beats all

basics

~20 s

DataDriftPreset picks a test from column type, unique-value count and reference size: at 1,000 reference rows or fewer, KS, chi-squared or a Z-test on p-values; above that, normed Wasserstein or Jensen-Shannon at 0.1. Pin it with method, num_method, cat_method or per_column_method.

solid answer

~50 s

With a reference of **1,000 rows or fewer**, a numerical column with more than five unique values (counted across both datasets) gets the two-sample KS test (`ks`), a categorical or low-cardinality column gets chi-squared (`chisquare`), or a Z-test (`z`) when it has two values or fewer, and drift is declared on a p-value at or under 0.05 (strictly under for chi-squared and the Z-test). With **more than 1,000** reference rows, numerical columns get normed Wasserstein (`wasserstein`) and categorical or low-cardinality ones Jensen-Shannon (`jensenshannon`), and drift is a score at or above 0.1. Dataset drift is declared when the drifted share reaches `drift_share` (0.5). To pin the choice, pass `method=` for every column, `num_method=` / `cat_method=` / `text_method=` by type, or `per_column_method={...}` by name, each with a matching `*_threshold`. A per-column setting beats a type setting, which beats `method`.

code

python · 11 lines
python
from evidently import Report
from evidently.presets import DataDriftPreset

preset = DataDriftPreset(
    num_method="wasserstein",
    cat_method="jensenshannon",
    per_column_method={"churn_score": "psi"},
    drift_share=0.5,
)
report = Report([preset], include_tests=True)
snapshot = report.run(current_week, reference)

go deeper

for a junior

Remember that Evidently picks a test per column from its type and the reference size, with a switch at 1,000 reference rows.

for a middle

Explain the full table: KS, chi-squared and Z-test on p-values for small references, normed Wasserstein and Jensen-Shannon on distances for large ones, plus drift_share and the override parameters.

for a senior

Show why an unpinned preset is a silent risk in a scheduled job: a resampled reference swaps methods and inverts the score's direction, so pin methods and record them.

for a principal

Argue for a shared, versioned drift configuration across models so scores stay comparable, rather than each team relying on the automatic choice.

## Why the automatic choice matters Evidently's `DataDriftPreset` does not apply one statistic to every column. For each column it picks a **drift method** (a statistical test or a distance) from three facts: the column's **type** (numerical, categorical or text), the **number of rows in the reference dataset**, and the column's **number of unique values**. The rule is sensible for exploration, but it has a consequence a monitoring job must plan for: if the reference sample changes size, for example from 900 rows to 5,000, every column can silently switch method, and with it the meaning and scale of its drift score. ## The default rule for tabular columns The counts below are of reference rows; the unique-value count is taken over the reference and current values together. | Reference size | Column | Default method | Score and drift condition | |---|---|---|---| | 1,000 rows or fewer | numerical, more than 5 unique values | `ks`, two-sample Kolmogorov-Smirnov | p-value; drift at 0.05 or below | | 1,000 rows or fewer | categorical, or numerical with 5 or fewer unique values | `chisquare` | p-value; drift below 0.05 | | 1,000 rows or fewer | 2 or fewer unique values | `z`, a proportion-difference Z-test | p-value; drift below 0.05 | | more than 1,000 rows | numerical, more than 5 unique values | `wasserstein`, distance normed by the reference standard deviation | distance; drift at 0.1 or above | | more than 1,000 rows | categorical, or numerical with 5 or fewer unique values | `jensenshannon` | distance; drift at 0.1 or above | Text columns use a domain classifier instead: one classifier variant at 1,000 rows or fewer, another above, both scored by ROC AUC. Two traps follow from the table: - A plan tier stored as the integers 1 to 4 is a numerical column, but with five or fewer unique values it is tested like a categorical one. - Below the switch a **smaller** score means more drift (a p-value); above it a **larger** score means more drift (a distance). A chart or alert that reads one regime reads the other backwards. How each statistic behaves on skewed or sparse data is a separate subject; here the point is which one Evidently picks and how to control it. ## How dataset drift is declared Each column first gets its own verdict. The preset then counts drifted columns and declares **dataset drift** when the share is at or above `drift_share`, 0.5 by default. `DataDriftPreset(drift_share=0.7)` raises the bar to 70%. ## Overriding the method and the threshold The preset accepts these parameters, each `None` by default (meaning "use the automatic choice"): - `method`, `threshold`: one method or threshold for every column. - `num_method`, `num_threshold`, `cat_method`, `cat_threshold`, `text_method`, `text_threshold`: by column type. - `per_column_method`, `per_column_threshold`: dictionaries keyed by column name. - `drift_share`: the dataset-level share. Resolution runs in this order: 1. A column named in `per_column_method` uses that method. 2. Otherwise the type-level method (`num_method`, `cat_method` or `text_method`) applies, if set. 3. Otherwise `method` applies, if set. 4. Otherwise the automatic rule in the table applies. Thresholds resolve the same way. Any method the library registers can be named, among them `psi`, `kl_div`, `hellinger`, `anderson`, `mannw` and `ed`, and a custom method can be registered too. ## Pinning the churn job For a weekly churn batch whose reference is resampled now and then, pin the methods so the scores mean the same thing every week: - set `num_method` and `cat_method` explicitly, so neither the reference size nor a low-cardinality column changes the test; - give the model's own score column its own entry in `per_column_method` if the team tracks it with a different statistic; - record the methods in the report's metadata or in code review, because the HTML shows the method per column but a dashboard built on raw scores does not. ## Edge cases worth knowing - Empty and infinite values are filtered out before the method runs, so a null spike needs its own data-quality test. - A column that is empty in either dataset raises an error instead of producing a score. - The `ValueDrift` metric takes the same `method` and `threshold` for a single column outside the preset.

  • A churn feature stored as the integers 1 to 4 is mapped as numerical. Which default test does Evidently apply to it?
    With five or fewer unique values across reference and current, it is treated like a categorical column: chi-squared at 1,000 or fewer reference rows (a Z-test if it had only two values) and Jensen-Shannon above that. Setting `num_method` overrides this, because the type-level method replaces the automatic choice for every numerical column.
  • Why do drift scores from a 900-row reference and a 5,000-row reference look incomparable?
    Below the 1,000-row switch the score is a p-value, where smaller means more drift and the cut is 0.05; above it the score is a distance, where larger means more drift and the cut is 0.1. Pin the method whenever the reference size can vary.

  • Says Evidently's drift preset uses PSI on every column by default
  • Thinks the current batch's size, not the reference's, selects the test
  • Reads a Wasserstein score of 0.03 as strong drift because it is under 0.05
  • Believes a method= setting cannot be overridden for a single column
  • Says dataset drift is declared as soon as any one column drifts

Assumes Evidently 0.7.23; the 1,000-row switch and default thresholds come from its stattest registry and drift docs, which earlier releases may not match.