Applying MLflow to an Existing Machine Learning Project
See how to apply MLflow to an existing machine learning project.
Join the DZone community and get the full member experience.Join For Free
What Is MLflow?
MLflow is an open-source platform to manage the ML lifecycle, including experimentation, reproducibility, deployment, and a central model registry. MLflow currently offers four components:
- MLflow Tracking
- MLflow Projects
- MLflow Models
- MLflow Registry
In this example, we are going to use an existing Keras Tensorflow example and add MLflow support to it.
Example: Collaborative Filtering for Movie Recommendations” with Keras and Tensorflow 2.0.0
The example we have selected is “Collaborative Filtering for Movie Recommendations” with Keras and Tensorflow 2.0.0. This example is created by Siddhartha Banerjee and the example Source URL is as below: https://keras.io/examples/structured_data/collaborative_filtering_movielens/
The GitHub source for the sample example is here:
Creating Necessary Files for MLflow:
- Download the source code on your local machine. Run the code locally to make sure it works and you understand it
$ python collaborative_filtering_movielens.py
- Create conda.yaml as below:
- Create MLProject as below:
command: “python collaborative_filtering_movielens.py”
Now you must have 3 files as below:
Editing the Code File for MLflow:
- Add the following python modules
- Comment matplotlib specific code in the project so plotting UI specific thread will not block the code execution.
# import matplotlib.pyplot as plt
# plt.title(“model loss”)
# plt.legend([“train”, “test”], loc=”upper left”)
That’s all. Now we will run the code in 2 separate terminal environments.
Environment 1: Open the MLflow UI
$ mlflow ui
Note: Please open your Web Browser with URL http://localhost:5000 to see the MLflow UI.
Environment 2: You can run the code with MLflow as below to start the project:
$ mlflow run .
Once code start running the MLflow UI will show the progress as below:
Source Code for This Project:
Project Walkthrough & Tutorial Video @ YouTube
That’s all. Please stay safe and stay healthy.
Published at DZone with permission of Avkash Chauhan, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Tech Hiring: Trends, Predictions, and Strategies for Success
Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
AI and Cybersecurity Protecting Against Emerging Threats
Knowing and Valuing Apache Kafka’s ISR (In-Sync Replicas)