Model Monitoring — MLflow

OCTAVE - John Keells Group
5 min readApr 21, 2023

--

By - Sanduni Jayasundara

Machine learning (ML) models are becoming increasingly important for businesses looking to gain insights from their data. However, managing these models can be a complex and time-consuming task. This is where MLflow comes in, a powerful tool for managing your ML models.

MLflow is an open-source platform that allows you to manage the entire machine learning lifecycle. From data preparation to model training and deployment, MLflow provides a unified interface for tracking and managing your ML projects.

Model monitoring is a crucial aspect of machine learning (ML) that helps maintain the performance of models and detect issues that may arise during deployment. To make this process easier and more efficient, MLflow offers a comprehensive set of tools for tracking and monitoring model performance. In this article, we’ll explore how to use MLflow to monitor models and ensure that they remain accurate and effective over time.

What is MLflow?

MLflow is an open-source platform for managing the entire machine learning lifecycle. It provides a unified interface for data scientists and engineers to track experiments, package code into reproducible runs, and share and deploy models.

MLflow consists of three main components: tracking, projects, and models. Each component plays a key role in the ML workflow, allowing you to track experiments, package code into reproducible runs, and deploy and manage models.

MLFLOW COMPONENTS

Tracking: The MLflow tracking component is an API and UI for logging parameters, code versions, metrics, and output files when running your machine learning code and for later visualizing the results. MLflow Tracking lets you log and query experiments using Python, REST, R API, and Java API APIs. MLflow Tracking is organized around the concept of runs, which are executions of pieces of data science code. Each run records the following information:

- Code version

- Start & End Time

- Source

- Parameters

- Metrics

- Artifacts

Projects: MLflow Projects are just a convention for organizing and describing your code to let other data scientists (or automated tools) run it. Each project is simply a directory of files, or a Git repository, containing your code. MLflow can run some projects based on a convention for placing files in this directory (for example, a conda.yaml file is treated as a Conda environment), but you can describe your project in more detail by adding a MLproject file, which is a YAML formatted text file. Each project can specify several properties:

- Name

- Entry Points

- Environment

Models: An MLflow Model is a standard format for packaging machine learning models that can be used in a variety of downstream tools. It provides a unified interface for tracking experiments, packaging code into reproducible runs, and sharing and deploying models.

An MLflow model is a standard format for packaging machine learning models that can be used across different ML frameworks and tools. It includes a model file, which contains the trained model parameters, as well as metadata such as the model’s input and output schema, version number, and any custom properties or dependencies. The model file can be easily loaded into a deployment environment, such as a web service or a batch scoring pipeline and used to make predictions on new data.

Model Monitoring with MLFlow

One of the key features in MLflow is the ability to capture detailed metrics for your models. The framework is not opinionated about what you should log. Instead, it provides a simple API for recording whatever data you might find useful.

a. Getting Started with MLflow Model Monitoring

To get started with model monitoring in MLflow, you’ll first need to install and set up the MLflow library. Once you’ve done that, you can start tracking your models by logging key metrics and parameters during training and deployment.

Below is an example of how to use MLflow to log key metrics during training:

Here, we use the mlflow.start_run() function to start a new MLflow run, which we can use to track our training process. Within the run, we train our model and then log key metrics using the mlflow.log_metric() function.

b. Monitoring Model Performance

Once we’ve logged metrics and parameters during training and deployment, we can use MLflow to monitor model performance over time. The MLflow UI provides a dashboard that displays key metrics and parameters for each run, allowing us to easily compare model performance and detect issues.

To access the MLflow UI, you can run the following command in your terminal:

This will start the MLflow UI, which you can access by navigating to http://localhost:5000 in your web browser.

In the MLflow UI, you can view key metrics and parameters for each run, as well as compare runs and track model performance over time. You can also set up alerts and notifications to detect issues automatically and take action when necessary.

These metrics can later be visualized via the MLflow server interface, which is super handy for tracking model metrics across different iterations of a model, or over time.

MLFLOW METRICS VISUALIZATION. SOURCE: MLFLOW

Conclusion

Model monitoring is a crucial aspect of machine learning that helps maintain the performance of models and detect issues that may arise during deployment. With MLflow, data scientists can easily track and monitor their models, log key metrics and parameters, and detect issues quickly and efficiently. By using MLflow to monitor model performance, data scientists can ensure that their models remain accurate and effective over time.

--

--

OCTAVE - John Keells Group
OCTAVE - John Keells Group

Written by OCTAVE - John Keells Group

OCTAVE, the John Keells Group Centre of Excellence for Data and Advanced Analytics, is the cornerstone of the Group’s data-driven decision making.

No responses yet