Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Model Monitoring: Purpose and Key Metrics

Hello! Welcome to the final lesson of our module on MLOps and Deployment.

In our last session, you successfully built a Docker image and ran your machine learning API as a container. Your model is now packaged and running in a portable, isolated environment. This is a significant achievement in making AI systems deployable.

But a question remains: now that your model is running, how do you know if it's still working well? A traditional web server might crash, giving a clear error. A machine learning model, however, can fail silently. It keeps providing predictions, but they might become inaccurate, biased, or irrelevant over time.

This lesson addresses that exact problem. We will explore the purpose of model monitoring and the common metrics to track in production. You will learn why a "deploy and forget" approach is dangerous and discover the framework for continuously ensuring your model remains valuable and reliable long after it's launched.

Why Bother Monitoring? The Inevitable Problem of Drift

The core assumption in machine learning is that the data used to train a model is a good representation of the data it will see in the real world. Unfortunately, the real world is not static. Customer behaviors change, new trends emerge, and the very definitions of things can evolve. This mismatch between the training world and the production world leads to a phenomenon called model drift.

Model drift is the degradation of a model's predictive power over time because the production environment has changed. It's one of the primary reasons we need to monitor our models.

To understand this better, let's watch a video that breaks down the concept of ML drift and its business impact.

ML Drift: Identifying Issues Before You Have a Problem

The following video from Fiddler AI clearly defines ML drift, explains why it happens, and highlights its potential financial and operational costs.

Please watch the segment from 00:14 to 02:23. Focus on the core assumption of machine learning and how changes in the real world violate it, leading to drift and its consequences.

As the video explains, drift is a serious issue. To monitor for it effectively, we need to distinguish between its different forms. The two primary types are Concept Drift and Data Drift.

Understanding Data Drift and Model Drift: Drift Detection in Python

This article from DataCamp provides a concise written explanation of the different types of drift. Reading this will solidify your understanding.

Please read the section titled 'Types of Drift', focusing on the definitions and examples for 'Concept Drift' and 'Data Drift'.

To summarize and visualize the key difference:

  • Concept Drift: The relationship between the input features and the target variable changes. The world's underlying rules have shifted.

    • Example: A loan approval model was trained when a certain income level was considered low-risk. After an economic downturn, that same income level is now high-risk. The input data's distribution might not have changed, but its meaning has.
  • Data Drift (or Covariate Shift): The statistical properties of the input features themselves change, but the underlying relationships remain the same.

    • Example: Your e-commerce site, which historically had users mostly from the USA, suddenly becomes popular in Europe. The new users have different browsing habits and income levels (data drift), but the factors that lead to a purchase (concept) may still be the same.
Concept Drift vs. Data Drift Illustration
This image illustrates the difference. On the left (Concept Drift), the user base distribution is the same, but what constitutes 'Spam' has changed. On the right (Data Drift), the user base itself has shifted from web to mobile, changing the input feature distribution.

Let's dig a bit deeper into these categories. The next video provides more concrete examples that will help you distinguish them.

ML Drift: Identifying Issues Before You Have a Problem

Let's return to the Fiddler AI video to see clear, practical examples that differentiate concept drift, data drift, and their sub-types (label drift, feature drift).

Watch the segment from 03:20 to 07:18. Pay attention to the loan application example used to explain each type of drift.

Understanding these types of drift is crucial because they tell you where to look when your model's performance starts to drop.

What to Monitor: A Framework of Key Metrics

Now that we know why we need to monitor, let's focus on what to monitor. A robust monitoring system doesn't just track a single number; it provides a holistic view of the ML system's health. We can group the metrics into four key categories.

ML Model Monitoring Dashboard Example
A typical monitoring dashboard shows multiple metrics at once, like prediction distribution, data drift, and operational volume, to give a complete picture of model health.

For a comprehensive overview of these categories, we'll turn to an excellent guide from Evidently AI.

Model monitoring for ML in production: a comprehensive guide

This guide, 'Model monitoring for ML in production', provides a structured approach to the metrics you need to track. It's a foundational resource for understanding this topic.

Please read the section 'Model monitoring metrics' and its introductory subsection '[fs-toc-omit]Metric overview'. This will introduce you to the four main pillars of ML monitoring.

As the article explains, we need to monitor:

  1. Software System Health: This is the foundation. Is the service up? Is it fast?

    • Metrics: Latency (response time), throughput (requests per second), server error rates (e.g., HTTP 5xx errors), CPU/Memory utilization.
    • Purpose: Ensures the container and API you just built are running reliably.
  2. Data Quality and Integrity: This is about the "Garbage In, Garbage Out" principle. Is the data fed to the model clean and as expected?

    • Metrics: Percentage of missing values, data type mismatches, values falling outside an expected range (e.g., age being negative), new categories appearing in a feature.
    • Purpose: Catches upstream data pipeline bugs or source changes before they cause the model to make nonsensical predictions.
  3. Model Performance (Predictive Quality): This is the most direct measure of the model's value. Is it making correct predictions?

    • Metrics: For classification: Accuracy, Precision, Recall, F1-score. For regression: Mean Absolute Error (MAE), Root Mean Squared Error (RMSE).
    • The Challenge: Ground Truth Delay. To calculate these metrics, you need the actual outcomes (the "ground truth"). For a fraud model, you might not know if a transaction was truly fraudulent for days. This delay is why we can't rely solely on performance metrics.
  4. Proxy Metrics for Drift (When Ground Truth is Delayed): When you can't measure performance directly, you monitor for drift as a proxy.

    • Output/Prediction Drift: Track the distribution of the model's predictions. If your model suddenly starts predicting "fraud" for 50% of transactions instead of the usual 1%, something has likely changed.
    • Input/Data Drift: Track the distribution of the input features. Are you suddenly seeing users with much higher average transaction amounts? This can be detected using statistical tests like the Kolmogorov-Smirnov (K-S) test for numerical features or the Chi-Squared test for categorical features. These tests compare the current data distribution to a baseline (e.g., the training data) to see if a statistically significant shift has occurred.

Let's watch a short video segment that reinforces how these different monitoring components fit into an MLOps pipeline.

MLOps Explained - What It Is, Why You Need It and How It Works

The 'MLOps Explained' video provides a great high-level view of how data validation and performance dashboards are integrated into a live system.

Please watch the following clips: Data Drift (16:11 - 16:55): Focus on how data validation tools constantly compare new data to training data. Dashboards (17:22 - 17:56): Notice the types of metrics displayed, like accuracy, processing speed, and false positive/negative rates. Continuous Monitoring (19:29 - 20:56): Understand how monitoring is an ongoing process that can trigger alerts and even automated actions like retraining.

The Monitoring Loop: From Detection to Action

Monitoring is not a passive activity. The goal is to create a feedback loop that maintains the health of your AI system. This loop generally follows these steps:

  1. Monitor: Continuously track metrics across the four categories using dashboards (like those built with tools such as Grafana or specialized ML monitoring platforms).
  2. Alert: Automatically trigger an alert (e.g., an email, a Slack message) when a metric crosses a predefined threshold (e.g., accuracy drops below 90%, or data drift is detected in a key feature).
  3. Analyze: Investigate the alert to find the root cause. Is it a bug in the data pipeline? Has the user population genuinely changed? Is it a new type of fraud?
  4. Act: Take corrective action based on the analysis. This could involve:
    • Fixing a data pipeline bug.
    • Retraining the model on new, more representative data.
    • Rolling back to a previous, more stable model version.
    • Triggering a manual review process for certain predictions.

This continuous cycle of monitor-alert-analyze-act is a cornerstone of MLOps and is what separates a fragile, one-off model from a robust, production-grade AI system.

Conclusion

Congratulations on completing the MLOps and Deployment module! You've gone from a trained model file to a fully containerized, running API, and now you understand the critical principles for keeping it healthy in the real world.

Key Takeaways:

  • Machine learning models in production suffer from "silent failures" due to drift, where performance degrades without crashing the application.
  • Model monitoring is the ongoing process of tracking metrics to detect and address these failures.
  • Drift comes in two main flavors: Concept Drift (the meaning of data changes) and Data Drift (the input data's distribution changes).
  • A comprehensive monitoring strategy tracks four key areas:
    1. Software Health (latency, errors)
    2. Data Quality (missing values, schema)
    3. Model Performance (accuracy, precision, etc.)
    4. Drift as a Proxy (prediction distribution, input feature drift)
  • The ultimate goal of monitoring is to enable an action loop to retrain, fix, or update the system to maintain its value.

Preview of the Next Module

So far, we've focused on classic ML models and the infrastructure to deploy them. Now, we're going to dive deep into one of the most powerful and exciting areas of AI: Computer Vision.

In our next module, Convolutional Neural Networks for Computer Vision, you will learn how to build models that can "see" and interpret images. We'll start from the ground up, exploring the fundamental building blocks of CNNs—convolutions and pooling layers—and build our first image classifier in PyTorch. Get ready to teach your models to understand the visual world

Can't find a good explanation? Sign up and we'll make it for you

Sign up