In NannyML, what does DomainClassifierCalculator catch that UnivariateDriftCalculator misses, and how does chunking change what each reports?
answer
- one score per column, or one overall
- a classifier telling reference from chunk
- AUROC near 0.5 means no drift
- a default band of 0.45 to 0.65
- about ten chunks unless told otherwise
basics
~20 sUnivariateDriftCalculator scores each column on its own, Jensen-Shannon by default. DomainClassifierCalculator trains LightGBM to tell reference rows from each chunk and reports cross-validated AUROC, so it catches changed relationships between features. Both score per chunk, and small chunks add noise.
solid answer
~40 s`UnivariateDriftCalculator(column_names=..., continuous_methods=..., categorical_methods=...)` gives one score per column per chunk; both method lists default to `['jensen_shannon']`, with `kolmogorov_smirnov`, `wasserstein`, `hellinger`, `chi2` and `l_infinity` available. Its alert thresholds come from the spread of each score across reference chunks. `DomainClassifierCalculator(feature_column_names=...)` labels reference rows 0 and chunk rows 1, trains LightGBM over `cv_folds_num=5` folds, and reports cross-validated AUROC; its threshold defaults to `ConstantThreshold(lower=0.45, upper=0.65)`. Because it learns from all features at once, it flags a chunk where the features' joint pattern changed while every single column's marginal distribution held. Chunking is set by `chunk_size`, `chunk_number`, `chunk_period` (which needs `timestamp_column_name`) or a `chunker`. Without one, NannyML splits each dataset into about 10 chunks, and it warns when the reference yields fewer than 6.
go deeper
Recall the split: univariate means one score per column, the domain classifier means one AUROC for all features, and both are computed per chunk.
Explain the defaults: jensen_shannon methods, standard-deviation thresholds from reference chunks, LightGBM with 5 folds and the 0.45 to 0.65 band, and how each chunking argument behaves.
Show the diagnostic flow: chunk by week, use the domain classifier to detect, the univariate view to localise, and performance estimation to judge impact, while watching reference chunk counts.
Weigh the compute cost of training a classifier per chunk across many models against the coverage it adds over cheap univariate scores.
## Two kinds of drift calculator **NannyML** (latest release 0.13.1) splits monitoring data into **chunks** and computes one result per chunk, for a **reference** period and for an **analysis** period. For input drift it offers two families: - **Univariate**: `UnivariateDriftCalculator` compares each column's distribution in a chunk with the reference, one column at a time. - **Multivariate**: `DomainClassifierCalculator` and `DataReconstructionDriftCalculator` produce one number per chunk that summarises all chosen features together. Each calculator is fitted on the reference (`fit(reference_df)`) and then run on new data (`calculate(analysis_df)`). The result's `to_df()` and `plot()` give a table and a chart of per-chunk values against thresholds. ## UnivariateDriftCalculator - Takes `column_names`, with optional `treat_as_numerical` and `treat_as_categorical` lists to override inferred types. - `continuous_methods` defaults to `['jensen_shannon']`; the other supported values are `kolmogorov_smirnov`, `hellinger` and `wasserstein`. - `categorical_methods` defaults to `['jensen_shannon']`; the other supported values are `chi2`, `hellinger` and `l_infinity`. - Several methods can be requested at once, and each produces its own series. - Default thresholds are standard-deviation thresholds with the lower bound switched off: a chunk alerts when its score rises well above the spread seen across the reference chunks. The result is easy to read per feature, which is exactly what makes it blind to one class of change: when each column's distribution stays the same but the **relationship between columns** changes. A churn example: tenure and monthly charges keep their individual distributions, but long-tenure customers now sit on the cheap plans instead of the expensive ones. ## DomainClassifierCalculator For every chunk it: 1. labels reference rows 0 and chunk rows 1, using the model inputs as features, and drops duplicate rows once; 2. encodes categorical columns as integers for LightGBM; 3. trains an `LGBMClassifier` with stratified cross-validation (`cv_folds_num=5` by default), optionally with hyperparameter tuning (`tune_hyperparameters=False` by default); 4. reports the **cross-validated AUROC** of telling the two apart. An AUROC near 0.5 means the classifier cannot tell the chunk from the reference. A higher AUROC means the chunk is easier to recognise, so it differs more. The default threshold is `ConstantThreshold(lower=0.45, upper=0.65)`. Because the classifier sees all features together, it catches the changed joint pattern that the univariate view missed. NannyML's docs warn that its AUROC does not translate directly into a performance impact: for that you use performance estimation. | | UnivariateDriftCalculator | DomainClassifierCalculator | |---|---|---| | Output per chunk | one score per column and method | one AUROC for all features | | Default method | `jensen_shannon` for both types | LightGBM, 5-fold cross-validation | | Default threshold | spread across reference chunks | constant band 0.45 to 0.65 | | Sees changed relationships between features | no | yes | | Points at the column that moved | yes | no, needs a follow-up univariate look | ## How chunking shapes both Every calculator accepts `chunk_size`, `chunk_number`, `chunk_period` or a ready `chunker`, and only one should be given. The choices matter: - **No chunking argument**: the default chunker splits each dataset into about 10 equal-size chunks. For a weekly batch job that rarely lines up with the weeks the team reasons about. - **`chunk_period`** (a pandas offset such as `"W"`) gives calendar chunks, and raises an error if `timestamp_column_name` is not set. - **Too few reference chunks**: thresholds learned from the reference rely on the variability across its chunks, and NannyML warns when there are fewer than 6. - **Too-small chunks**: results become dominated by sampling noise, and for the domain classifier a small chunk gives the cross-validation little to learn from. ## Reading the output - `results.to_df()` returns one row per chunk with the score, the threshold bounds and an alert flag for each method or metric, for reference and analysis chunks alike. - `results.plot()` draws the same series with the thresholds, which is the quickest way to see whether an alert is a single spike or a trend. - Reference chunks appear in the output too. Alerts inside the reference period usually mean the thresholds are too tight or the reference itself is unstable. ## Using them together A sound pattern for a weekly churn batch is to chunk by week, run the domain classifier as the single "has anything moved?" signal, and open the univariate results for the weeks it flags to see which columns moved. Which signals deserve a chart in the first place, and what the alert should do, are design decisions made outside the library.
- Why can NannyML's domain classifier flag a churn chunk while every univariate Jensen-Shannon score stays inside its threshold?Univariate scores compare each column's marginal distribution on its own. The domain classifier learns from all features together, so it picks up a changed combination, such as long-tenure customers moving to cheap plans, even when each column's distribution looks unchanged.
- What goes wrong if a NannyML calculator is run on a weekly churn feed with no chunking argument?The default chunker splits each dataset into about 10 equal-size chunks, which need not match calendar weeks, so a chunk can straddle two weeks. Set `chunk_period="W"` with `timestamp_column_name`, or a `chunk_size` that matches one batch, and keep at least 6 reference chunks.
The domain classifier is like a blind taster handed two batches of wine: if they can reliably say which glass came from which batch, the batches differ, even when sweetness and acidity measured one at a time look identical. A taster scoring near chance, about 0.5, means no detectable difference.
- Reads a domain-classifier AUROC of 0.5 as maximal drift
- Expects the domain classifier to name which column drifted
- Thinks UnivariateDriftCalculator defaults to the KS test for numerical columns
- Believes chunk_period works without a timestamp column
- Treats the domain classifier's AUROC as the size of the performance drop
Assumes NannyML 0.13.1 (2025-07-12, the latest release as of 2026-10-05); defaults are from its drift calculators and chunk.py.