blog bg left
Back to Blog

ML Monitoring in Under 5 Minutes

It only takes a few minutes and a few lines of code to monitor your ML models and data pipelines.  

Data validation and ML model monitoring are foundational steps to building reliable pipelines and responsible machine learning applications.

In this short post, I will show you how to use an open source data logging library and an AI observatory platform to monitor common issues with your ML models, such as data drift, concept drift, data quality, and performance.

Data logging and ML monitoring setup

First, we’ll install whylogs, an open-source data logging library that captures key statistical properties of data. We’ll also include dependencies for writing to the WhyLabs AI observatory for ML monitoring.

pip install “whylogs[whylabs]

Next, we’ll import the `whylogs`,`pandas`, and `os` libraries into our Python project. We’ll also create a dataframe of our dataset to profile.

import whylogs as why
import pandas as pd
import os
# create dataframe with dataset
dataset = pd.read_csv("")

The data profiles created with whylogs can be used on their own for data validation and data drift visualization, but in this example, we’re going to write profiles to the WhyLabs Observatory to perform ML monitoring.

In order to write profiles to WhyLabs, we’ll create an account and grab our `Org-ID`, `Access token`, and `Project-ID` to set them as environment variables in our project.

# Set WhyLabs access keys

Create a free WhyLabs account here, no credit card required.

Create a new project and get the ID:

Create Project > Set up model > Create Project

Create Project in WhyLabs

Get organization ID and access token:

Menu > Settings > Access Tokens > Create Access Token

Create an Access Token in WhyLabs

That’s it for setting up. We can now write data profiles to WhyLabs.

Write profiles to WhyLabs for ML monitoring

Once the access keys are set up, we can easily create a profile of your dataset  and write it to WhyLabs. This allows us to monitor input data and model predictions with just a few lines of code!

# initial WhyLabs writer, Create whylogs profile, write profile to WhyLabs
writer = WhyLabsWriter()
profile= why.log(dataset)

Profiles can be created at any stage of a pipeline allowing you to monitor data at every step.

By default the time stamp will be the time of the profile upload, but it can be overwritten to log data from different collection times and backfill profiles.

You can see an example of writing and backfilling data in this notebook.

Once profiles are written to WhyLabs they can be inspected, compared, and monitored for data quality and data drift.

Comparing and Inspecting Profiles in WhyLabs

Now we can enable a pre-configured monitor with just one click (or create a custom one) to detect anomalies in our data profiles. This makes it easy to set up common monitoring tasks, such detecting data drift, data quality issues, and model performance.

Enabling a Pre-configured Monitor

Once a monitor is configured, it can be previewed while inspecting an input feature.

Data Drift Detected With ML Monitoring in WhyLabs

When anomalies are detected, notifications can be sent via email, Slack, or PagerDuty. Set notification preferences in Settings > Notifications & Digest Settings.

Setting Up Notifications in WhyLabs

That’s it! We have gone through all the steps needed to ingest data from anywhere in ML pipelines and get notified if anomalies occur.

Separating model input and outputs

It can be useful to separate model inputs and outputs, especially if you have a lot of features in your input data. Any features with names that contain the word “output” will appear in the outputs tab.

Monitoring model performance metrics

So far we’ve seen how to monitor model input and output data, but we can also monitor performance metrics such as accuracy, precision, etc. by logging ground truth with our prediction results.

To log performance metrics for monitoring use `why.log_classification_metrics` or `why.log_regression_metrics` and pass in a dataframe containing ground truth our model output results.

results = why.log_classification_metrics(
         target_column = "ground_truth",
         prediction_column = "cls_output",
 profile = results.profile() 
Note: Make sure your project is configured as a classification or regression model in the settings.

Just like the input data, performance metrics get uploaded with the current timestamp unless overwritten. See an example of backfilling data for performance monitoring in the example notebooks below.

Backfilling Data for Performance Monitoring in WhyLabs

Again we can select a pre-configured monitor to detect any change in performance.

See example notebooks for classification and regression monitoring on our GitHub.

Recap on ML monitoring

We covered how to quickly set up data and ML monitoring solutions that can be used at any point in your pipeline! With the right tools, ML monitoring can only take a few minutes with a few lines of code.

We barely scratched the surface of whylogs and WhyLabs features. If you’d like to learn more, request a demo or sign-up for free and explore the features yourself!

Example notebooks mentioned in this post:

Ready to implement data & ML monitoring in your own applications?

Other posts

How to Troubleshoot Embeddings Without Eye-balling t-SNE or UMAP Plots

WhyLabs' scalable approach to monitoring high dimensional embeddings data means you don’t have to eye-ball pretty UMAP plots to troubleshoot embeddings!

Robust & Responsible AI Newsletter - Issue #5

Every quarter we send out a roundup of the hottest MLOps and Data-Centric AI news including industry highlights, what’s brewing at WhyLabs, and more.

Detecting Financial Fraud in Real-Time: A Guide to ML Monitoring

Fraud is a significant challenge for financial institutions and businesses. As fraudsters constantly adapt their tactics, it’s essential to implement a robust ML monitoring system to ensure that models effectively detect fraud and minimize false positives.

Achieving Ethical AI with Model Performance Tracing and ML Explainability

With Model Performance Tracing and ML Explainability, we’ve accelerated our customers’ journey toward achieving the three goals of ethical AI - fairness, accountability and transparency.

Detecting and Fixing Data Drift in Computer Vision

In this tutorial, Magdalena Konkiewicz from Toloka focuses on the practical part of data drift detection and fixing it on a computer vision example.

BigQuery Data Monitoring with WhyLabs

We’re excited to announce the release of a no-code solution for data monitoring in Google BigQuery, making it simple to monitor your data quality without writing a single line of code.

Robust & Responsible AI Newsletter - Issue #4

Every quarter we send out a roundup of the hottest MLOps and Data-Centric AI news including industry highlights, what’s brewing at WhyLabs, and more.

WhyLabs Private Beta: Real-time Data Monitoring on Prem

We’re excited to announce our Private Beta release of an extension service for the Profile Store, enabling production use cases of whylogs on customers' premises.

Understanding Kolmogorov-Smirnov (KS) Tests for Data Drift on Profiled Data

We experiment with statistical tests, Kolmogorov-Smirnov (KS) specifically, applied to full datasets and dataset profiles and compare the results.
pre footer decoration
pre footer decoration
pre footer decoration

Run AI With Certainty

Book a demo