Skip to content

Latest commit

 

History

History
166 lines (113 loc) · 7.2 KB

univariate_drift_detection.rst

File metadata and controls

166 lines (113 loc) · 7.2 KB

Univariate Drift Detection

Why Perform Univariate Drift Detection

Univariate Drift Detection looks at each feature individually and checks whether its distribution has changed. It's a simple, fully explainable form of data drift detection and is the most straightforward to understand and communicate.

Just The Code

Walkthrough

NannyML's Univariate approach for data drift looks at each variable individually and conducts statistical tests comparing the chunks<chunking> created from the analysis data period<data-drift-periods> with the reference period. You can read more about the data required in our section on data periods<data-drift-periods>

NannyML uses the 2 sample Kolmogorov-Smirnov Test<Kolmogorov-Smirnov test> for continuous features and the Chi squared test<Chi Squared test> for categorical features. Both tests provide a statistic where they measure the observed drift and a p-value that shows how likely we are to get the observed sample under the assumption that there was no drift.

If the p-value is less than 0.05 NannyML considers the result unlikely to be due to chance and issues an alert for the associated chunk and feature.

We begin by loading some synthetic data provided in the NannyML package. This is data for a binary classification model, but other model types operate in the same way.

The ~nannyml.drift.model_inputs.univariate.statistical.calculator.UnivariateStatisticalDriftCalculator class implements the functionality needed for Univariate Drift Detection. We need to instantiate it with appropriate parameters - the column headers of the features that we want to run drift detection on, and the timestamp column header. The features can be passed in as a simple list of strings, but here we have created this list by excluding the columns in the dataframe that are not features, and passed that into the argument.

Next, the ~nannyml.drift.model_inputs.univariate.statistical.calculator.UnivariateStatisticalDriftCalculator.fit method needs to be called on the reference data, which provides the baseline that the analysis data will be compared with. Then the ~nannyml.drift.model_inputs.univariate.statistical.calculator.UnivariateStatisticalDriftCalculator.calculate method will calculate the drift results on the data provided to it.

We then display a small subset of our results by specifying columns in the ~nannyml.drift.model_inputs.univariate.statistical.calculator.UnivariateStatisticalDriftCalculator.calculate.results method.

NannyML returns a dataframe with 3 columns for each feature. The first column contains the corresponding test statistic. The second column contains the corresponding p-value and the third column says whether there is a drift alert for that feature and chunk.

The drift results from the reference data are accessible though the previous_reference_results property of the drift calculator:

NannyML can also visualize those results on plots.

image

image

image

image

image

image

NannyML also shows details about the distributions of continuous variables and categorical variables. For continuous variables NannyML plots the estimated probability distribution of the variable for each chunk in a plot called joyplot. The chunks where drift was detected are highlighted. We can create joyplots for the model's continuous variables with the code below:

image

image

image

image

NannyML can also plot details about the distributions of different features. In these plots, NannyML highlights the areas with possible data drift. If we want to focus only on the categorical plots, we can specify that only these be plotted.

For categorical variables NannyML plots stacked bar charts to show the variable's distribution for each chunk. If a variable has more than 5 categories, the top 4 are displayed and the rest are grouped together to make the plots easier to view. We can stacked bar charts for the model's categorical variables with the code below:

image

image

image

NannyML can also rank features according to how many alerts they have had within the data analyzed for data drift. NannyML allows viewing the ranking of all the model inputs, or just the ones that have drifted. NannyML provides a dataframe with the resulting ranking of features.

Insights

After reviewing the above results we have a good understanding of what has changed in our model's population.

What Next

The Performance Estimation<performance-estimation> functionality of NannyML can help provide estimates of the impact of the observed changes to Model Performance.

If needed, we can investigate further as to why our population characteristics have changed the way they did. This is an ad-hoc investigating that is not covered by NannyML.