Training data and data arriving in production diverge over time. If you miss this change (data drift), you can keep using the model without noticing its declining accuracy. Evidently compares reference data with current data through statistical tests and detects columns whose distributions have changed. I installed it and tested drift detection with the network disconnected.
Evidently compares two datasets, reference data and current data, with statistical tests and determines whether each column's distribution has changed. The project uses the Apache 2.0 License for its source code (*1).
1. Install Evidently
FROM docker.io/library/python:3.12.13-slim
RUN pip install --no-cache-dir --quiet 'evidently==0.7.21' 'pandas==2.3.3'
WORKDIR /work
podman build -t evidently-sandbox .
2. Compare datasets with one shifted column
Prepare two synthetic datasets with two columns (request size and response time), then shift only the request-size distribution (mean 50→90). Keep the response-time distribution close to its original form. Run the test with the network disconnected.
import numpy as np
import pandas as pd
from evidently import Report
from evidently.presets import DataDriftPreset
rng = np.random.default_rng(0)
reference = pd.DataFrame({
"request_size_kb": rng.normal(50, 10, 500),
"response_time_ms": rng.normal(120, 20, 500),
})
current = pd.DataFrame({
"request_size_kb": rng.normal(90, 12, 500),
"response_time_ms": rng.normal(122, 21, 500),
})
report = Report(metrics=[DataDriftPreset()])
result = report.run(reference_data=reference, current_data=current)
for metric in result.dict()["metrics"]:
print(metric["metric_name"], "->", metric["value"])
podman run --rm --network none --memory 2g --cpus 2 --pids-limit 512 \
-v "$(pwd)":/work -w /work evidently-sandbox \
python drift_demo.py
The -v option lets the container read and write the specified directory. Run this command from an empty directory dedicated to the experiment.
The command produced this output:
DriftedColumnsCount(drift_share=0.5) -> {'count': 1.0, 'share': 0.5}
ValueDrift(column=request_size_kb,method=K-S p_value,threshold=0.05) -> 5.55445064188456e-244
ValueDrift(column=response_time_ms,method=K-S p_value,threshold=0.05) -> 0.058689209417416795
Evidently classified one of the two columns as drifted (count: 1.0). For the shifted request_size_kb column, the Kolmogorov–Smirnov test returned a p-value near zero (5.55e-244), so Evidently classified the column as drifted. For the response_time_ms column, which remained close to its original distribution, the test returned a p-value of 0.0587, a narrow margin above the default threshold (0.05), so Evidently classified the column as having no drift. Evidently detected the shifted column and no other.
Catch Declines in Model Accuracy
Production data distributions will change over time. Run a statistical test such as Evidently's at regular intervals so you do not keep using the model without noticing a shift. You can use the measurements to identify which input column changed and when, instead of relying on a hunch that the model's accuracy has declined.
Sources
*1 Evidently (GitHub), https://github.com/evidentlyai/evidently, Apache 2.0 License