Lesson 2 of 4 Model Monitoring in Azure Machine Learning

Detecting and Analyzing Data Drift

This lesson explains drift metrics, the choice of reference data and windows, how drift signals are configured, and how drift results are analyzed before retraining.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify drift metrics for numerical and categorical features.
  • Choose reference data for gradual or sudden drift.
  • Describe a drift signal configuration.
  • Explain what to check before retraining.

Drift metrics

Drift is measured per feature by comparing the feature's distribution in the production window with its distribution in the reference window. Different metrics suit numerical and categorical features, and each has a threshold above which the feature is considered drifted.

MetricFeature typeInterpretation
Jensen-Shannon distanceNumerical and categorical0 means identical distributions; larger values mean more difference (bounded)
Population Stability Index (PSI)Numerical and categoricalA common rule of thumb: below 0.1 little change, 0.1 to 0.25 moderate, above 0.25 significant
Normalized Wasserstein distanceNumericalThe effort to transform one distribution into the other, normalized
Two-sample Kolmogorov-Smirnov testNumericalThe largest difference between cumulative distributions, as a statistical test
Pearson's chi-squared testCategoricalWhether category frequencies differ significantly

Statistical tests become very sensitive with large samples: with millions of rows, tiny, harmless differences become statistically significant. Distance metrics such as Jensen-Shannon distance and PSI express the size of the change, which is usually more useful for deciding whether to act.

Reference data and windows

The choice of reference decides what counts as drift. Comparing with the training data asks whether production still resembles what the model learned from, which is the question that matters for model validity. Comparing with recent past production data, such as the previous week, asks whether something changed suddenly, which catches upstream breakages quickly but can miss slow drift.

Training data as reference
DetectsGradual drift away from what the model learned
Sensitivity to seasonalityHigh: seasonal patterns can look like drift
Best forDeciding when to retrain
Choose when You want to know whether the model is still valid
Recent production as reference
DetectsSudden changes between periods
Sensitivity to seasonalityLower, if windows cover similar periods
Best forDetecting upstream data incidents
Choose when You want to catch breaks quickly

Windows are set with ISO 8601 durations. By default, the production window matches the monitoring frequency, such as one day for a daily monitor, and a production-based reference uses a window twice the production window's size, offset into the past. Fixed reference windows can be set with start and end dates.

Configuring a drift signal

A monitor is created as a schedule with a create_monitor section. Basic monitoring needs only the deployment, from which Azure Machine Learning sets up default signals; advanced monitoring names each signal with its data, features and thresholds.

$schema: http://azureml/sdk-2-0/Schedule.json
name: churn-monitor
trigger:
  type: recurrence
  frequency: day
  interval: 1
  schedule:
    hours: 3
    minutes: 0
create_monitor:
  compute:
    instance_type: standard_e4s_v3
    runtime_version: "3.4"
  monitoring_target:
    ml_task: classification
    endpoint_deployment_id: azureml:churn-ep:blue
  monitoring_signals:
    training_drift:
      type: data_drift
      alert_enabled: true
      reference_data:
        input_data:
          path: azureml:churn-train:3
          type: mltable
        data_context: training
        target_column_name: churned
      features:
        top_n_feature_importance: 10
      metric_thresholds:
        numerical:
          jensen_shannon_distance: 0.05
        categorical:
          pearsons_chi_squared_test: 0.05
  alert_notification:
    emails:
      - [email protected]
az ml schedule create --file monitors/churn-monitor.yml -g rg-ml-prod -w mlw-churn-prod

Monitoring jobs run on serverless Spark compute, set by the instance type and runtime version. top_n_feature_importance limits the signal to the most important features, which reduces noise from irrelevant columns. Each signal sends notifications only when alert_enabled is true, so a monitor whose signals leave it unset records breaches in the studio without emailing anyone.

Analyzing drift results

The studio's monitoring overview shows each signal's status over time, and the feature details show which features drifted, by how much, and their distributions in each window. The analysis then asks whether the drift matters.

  • Is the feature important? Drift in a feature the model barely uses changes little. Feature importance, and the feature attribution drift signal, answer this.
  • Is the drift real or an artifact? A sudden jump in nulls or a new category often means an upstream change, which is a data quality fix rather than a retraining case.
  • Is it seasonal? December traffic differs from July every year; a reference that includes the same season avoids false alarms.
  • Did predictions shift? Prediction drift alongside data drift suggests the model's behaviour is changing.
  • Did performance fall? Ground truth confirms whether accuracy actually declined.

Drift is not always a retraining signal

Retraining is not the answer to every drift alert. If drift comes from a broken upstream pipeline, such as a field now recorded in different units, retraining would teach the model the error. Fix the data first.

Worked example

Too many alerts

A drift monitor on a model with 180 features sends alerts almost every day. Investigation shows that most alerts concern features with negligible importance, and that several use the chi-squared test on categories with millions of rows, where tiny changes are significant. The team wants alerts that indicate meaningful drift.

Limit the signal to the most important features with top_n_feature_importance, and use a distance metric such as Jensen-Shannon distance or PSI with thresholds based on the size of change that matters, rather than significance tests that flag tiny differences in large samples. Adding the feature attribution drift signal shows whether drift affects what the model relies on.

Disabling the drift signal would remove the early warning. Monitoring weekly instead of daily would reduce the number of alerts but not their relevance. Removing low-importance features from the model would require retraining and is a modelling decision, not a monitoring fix.

Check yourself

Why use the training data as the reference for a drift signal instead of last week's production data?

Show answer

Training data reveals gradual drift away from what the model learned. Recent production data reveals sudden changes but hides slow drift, because each window resembles the previous one.

Exam Tips

Remember for the exam

  • Drift metrics: Jensen-Shannon distance, PSI, Normalized Wasserstein, Kolmogorov-Smirnov, chi-squared.
  • Training data as reference detects gradual drift; recent production detects sudden changes.
  • Configure monitors as schedules with create_monitor; top_n_feature_importance reduces noise.
  • Check importance, upstream changes, seasonality and performance before retraining.