Data drift algorithm
In some tests and metrics, Evidently uses the default Data Drift Detection algorithm. It helps detect the distribution drift in the individual features, prediction, or target. This page describes how the default algorithm works.
How it works
Evidently compares the distributions of the values in a given column (or columns) of the two datasets. You should pass these datasets as reference and current. Evidently applies several statistical tests and drift detection methods to detect if the distribution has changed significantly. It returns a "drift detected" or "not detected" result.
There is a default logic to choosing the appropriate drift test for each column. It is based on:
column type: categorical, numerical, text data or embeddings
the number of observations in the reference dataset
the number of unique values in the column (n_unique)
Tabular Data
![](https://docs.evidentlyai.com/~gitbook/image?url=https%3A%2F%2F256125905-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FeE67gM4508ESQxkbpOxj%252Fuploads%252Fgit-blob-a75fbd93777e730afb102527718d5b142f6dbfdb%252Fmetric_data_drift_table_2-min.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=82bd861f&sv=1)
For small data with <= 1000 observations in the reference dataset:
For numerical columns (n_unique > 5): two-sample Kolmogorov-Smirnov test.
For categorical columns or numerical columns with n_unique <= 5: chi-squared test.
For binary categorical features (n_unique <= 2): proportion difference test for independent samples based on Z-score.
All tests use a 0.95 confidence level by default.
For larger data with > 1000 observations in the reference dataset:
For numerical columns (n_unique > 5):Wasserstein Distance.
For categorical columns or numerical with n_unique <= 5):Jensen--Shannon divergence.
All metrics use a threshold = 0.1 by default.
You can always modify this drift detection logic. You can select any of the statistical tests available in the library (including PSI, K-L divergence, Jensen-Shannon distance, Wasserstein distance, etc.), specify custom thresholds, or pass a custom test. You can read more about using data drift parameters and available drift detection methods.
Text Data
![](https://docs.evidentlyai.com/~gitbook/image?url=https%3A%2F%2F256125905-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FeE67gM4508ESQxkbpOxj%252Fuploads%252Fgit-blob-a57bd7d2e85795086e684893ae26822b75259f1f%252Fmetric_column_drift_text-min.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=b061ec23&sv=1)
Text content drift using a domain classifier. Evidently trains a binary classification model to discriminate between data from reference and current distributions.
The default for small data with <= 1000 observations detects drift if the ROC AUC of the drift detection classifier > possible ROC AUC of the random classifier at a 95th percentile.
The default for larger data with > 1000 observations detects drift if the ROC AUC > 0.55.
You can set different thresholds. You can specify a custom threshold as a parameter.
Text Descriptors Drift
![](https://docs.evidentlyai.com/~gitbook/image?url=https%3A%2F%2F256125905-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FeE67gM4508ESQxkbpOxj%252Fuploads%252Fgit-blob-a33af2565bb54fe56af397233ce3caead61407a7%252Fmetric_text_descriptors_drift-min.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=8f617054&sv=1)
You can also check for drift in Text Descriptors. There is an additional method that detects drift in Text Descriptors (such as text length, share of OOV words). This test is available as part of Text Overview Preset. You can also include it as a TextDescriptorsDriftMetric() in a custom Report, or in a Test Suite accordingly.
The descriptors are treated as tabular features. The default drift detection methods for tabular features apply.
Embeddings
![](https://docs.evidentlyai.com/~gitbook/image?url=https%3A%2F%2F256125905-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FeE67gM4508ESQxkbpOxj%252Fuploads%252Fgit-blob-c0edce15d405a8aba7653bc4f592e35ccb9d05a4%252Fmetric_embeddings_drift.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=702cdc1b&sv=1)
Embedding drift using a classifier. Evidently trains a binary classification model to discriminate between data from reference and current distributions.
The default for small data with <= 1000 observations detects drift if the ROC AUC of the drift detection classifier > possible ROC AUC of the random classifier at a 95th percentile.
The default for larger data with > 1000 observations detects drift if the ROC AUC > 0.55.
You can choose other embedding drift detection methods. You can specify custom thresholds and parameters such as dimensionality reduction and choose from other methods, including Euclidean distance, Cosine Similarity, Maximum Mean Discrepancy, and share of drifted embeddings. You must specify this as a parameter.
Dataset-level drift
With Presets like DatasetDriftPreset()
, Metrics like DatasetDriftMetric()
or Tests like TestShareOfDriftedColumns()
you can also set a rule on top of the individual feature drift results to detect dataset-level drift.
For example, you can declare dataset drift if 50% of all features (columns) drifted or if ⅓ of the most important features drifted. The default in DatasetDriftPreset()
is 0.5.
Note that by default this includes all columns in the dataset. Suppose your dataset contains the prediction column, and you want to separate it from input drift detection. In that case, you should pre-process your dataset to exclude it or specify a list of columns you want to test for drift, and pass the list as a parameter.
![](https://docs.evidentlyai.com/~gitbook/image?url=https%3A%2F%2F256125905-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FeE67gM4508ESQxkbpOxj%252Fuploads%252Fgit-blob-41d198e2706e14e1a06b53f136be2bd03b5f1c70%252Freport_example_data_drift-min.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=b56df91d&sv=1)
You can set different thresholds. You can specify a custom threshold as a parameter.
Input data requirements
Empty columns
To evaluate data or prediction drift in the dataset, you need to ensure that the columns you test for drift are not empty. If these columns are empty in either reference or current data, Evidently will not calculate distribution drift and will raise an error.
Empty values
If some columns contain empty or infinite values (+-np.inf), these values will be filtered out when calculating distribution drift in the corresponding column.
By default, drift tests do not react to changes or increases in the number of empty values. Since the high number of nulls can be an important indicator, we recommend grouping the data drift tests (that check for distribution shift) with data integrity tests (that check for a share of nulls). You can choose from several null-related tests and metrics and set a threshold.
Resources
To build up a better intuition for which tests are better in different kinds of use cases, you can read our in-depth blogs with experimental code:
Additional links:
Last updated