Drift Detection
Last updated
Last updated
When ML models are deployed in production, sometimes even minor changes in a data distribution can adversely affect the performance of ML models. When the input data distribution shifts then prediction quality can drop. It is important to track this drift. This demo is based on the mixed-type tabular data drift detection method in the alibi detect project for tabular datasets.
Here we will:
Launch a Seldon ML pipeline with the income classifier model.
Setup a mixed-type tabular data drift detector for this particular model.
Make a batch of predictions over time
Track the drift metrics in the Monitoring dashboard.
This demo uses a model trained to predict high or low income based on demographic features from a 1996 US census.
Deploy the income classifier model from the catalog into an appropriate namespace
From the model catalog, under the Action
dropdown list, select Deploy
.
Enter the deployment details in the deployment creation wizard and click Next
:
Name: income-drift-demo
Namespace: seldon
Type: Seldon ML Pipeline
The predictor details should already be filled in from the model catalog. Click Next
:
Click Next
for the remaining steps, then click Launch
.
From the deployment overview page, select your deployment to enter the deployment dashboard. Inside the deployment dashboard, add a drift detector with by clicking the Add
button within the DRIFT DETECTION
widget.
Enter the following parameters in the modal popup which appears, to configure the detector:
Detector Name: income-drift
.
Model URI: (For public google buckets, secret field is optional)
Reply URL: (By default, the Reply URL is set as seldon-request-logger
in the logger's default namespace. If you are using a custom installation, please change this parameter according to your installation.)
Minimum Batch Size: 200
Drift Type: Feature
Then, click Create Detector
to complete the setup.
As per the income classifier model, use the same model predictions schema income-classifier-prediction-schema.json
to edit and save the model level metadata for drift detector.
Click on the vertical ellipses “⋮” icon for the drift detector you have just registered.
Click the Configure Metadata
option to update the prediction schema associated with the model
Paste the downloaded income-classifier-prediction-schema.json
, name the model income-drift
and click Save Metadata
.
From the deployment dashboard, click on Batch Jobs
. Run a batch prediction job using the Open Inference Protocol (OIP) payload format text predictions data file data.txt
.
This file has 4000 individual data points and based on our drift detector configuration, drift will be detected for a batch every 200
points. The distribution of the data in the first half section is the same as the distribution of the reference data the drift detector was configured with and the second half section of the data should be different to observe drift.
Upload the data to a bucket store of your choice. This demo will use MinIO and store the data at bucket path minio://income-batch-data/data.txt
. Do not forget to configure your storage access credentials secret - we have it as minio-bucket-envvars
here. Refer to the batch request demo for an example of how this can be done via the minio browser.
Running a batch job with the configuration below. This runs an offline job that makes a prediction request for a batch of 200 rows in the file at minio://income-batch-data/data.txt
every 5 seconds
:
Under the Monitor
section of your deployment navigation, on the Drift Detection
Tab, you can see a timeline of drift detection metrics.
The drift dashboard showcases 2 types of metrics graphs:
P-value score over time
Zoomed in view, focusing on features that have drifted, i.e. features that have a p-value score of less than the threshold.
Zoomed out view, showing all features.
Distance score over time.
If you have alerting configured you should see a notification about the drift
with further details present on the alerting log
To further analyse prediction data drift, you can also switch to the feature distribution tab to compare predictions to reference data distribution. See feature distribution monitoring demo for setup details.
Upload the income classifier reference dataset drift-reference-v2.csv
as the reference data to monitor data drift in terms of feature distributions.
Once reference data is available, you can compare the distributions of the prediction data to the reference data.
You can see when reference data is available by checking the button on the top left of the Distributions
dashboard. If it is not clickable and displays Reference data available
, then reference data is available.
For each feature, you can click on Toggle reference data
to view reference data side by side.
We will see that the drifted data has lower education individuals that were not in the reference data.
If you experience issues with this demo, see the troubleshooting docs or Elasticsearch sections.
Register a pre-trained income classifier SKLearn model.
In the Model Catalog
page, click Register a new model
:
In the Register New Model
wizard, enter the following information, then click Register Model
:
Model Name: income-classifier
URI: gs://seldon-models/scv2/samples/mlserver_1.6.0/income-sklearn/classifier/
Artifact Type: SciKit Learn
Version: v1
Edit the model metadata to update the prediction schema for the model. The prediction schema is a generic schema structure for machine learning model predictions. It is a definition of feature inputs and output targets from the model prediction. Learn more about the predictions schema at the ML Predictions Schema open source repository. Use the income classifier model predictions schema income-classifier-prediction-schema.json
to edit and save the model level metadata.
Click the model income-classifier
that you registered.
Click Edit Metadata
to update the Prediction schema field associated with the model using the contents of prediction schema income-classifier-prediction-schema.json
.
Click Save Metadata
.