Fast Data Quality check based on the adversarial validation algorithm

Maxim Shalankin27 May 2024

Problem

The data-science team at MTS Fintech builds data marts on a Hadoop cluster, and ML models train on them. Large volumes and varied table structures make errors expensive and hard to find. The team needs a check that compares today's partition with an earlier reference partition, works on many columns of any type, and finishes fast enough to sit inside scheduled pipelines.

Example from the article: one day a categorical feature in a table broke: its distribution changed strongly and many values appeared that had not been there before.

Solution in brief

Train a small gradient-boosting classifier to tell the reference partition from the new one. Its ROC AUC says whether the data changed (near 0.5 means no change, near 1 means a strong change), and its feature importance points to the broken column. The check runs as a Spark pandas UDF and as one extra step in the Airflow DAG that writes the mart.

Questions this case answers
  • How to detect distribution shift between a new data batch and a reference batch across many columns at once, in a single cheap pass, and see which columns changed
  • How to detect that a freshly written data mart has drifted from a reference partition before an ML model trains on it?
  • How to find which column broke when a table changes, without writing a custom check per column?
  • How to run a data-quality check on a large Hadoop/Spark cluster without slowing down regular pipelines?

Tools and methods

  • Adversarial validation — the classifier-based drift check that gives one table-level score plus per-column importance.
  • CatBoost — the adversarial classifier, with iterations=20; LightGBM or XGBoost also fit.
  • Apache Spark (applyInPandas) — runs the check per batch of rows across the cluster.
  • Apache Airflow — runs the check as a separate DAG step after the data is written.
  • PSI and Kolmogorov-Smirnov statistic — per-column baselines the author compared against.
Continue reading — it's free

Google or a one-time email code. No password.