DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • 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)

Trending

  • 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)
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Applying MLflow to an Existing Machine Learning Project

Applying MLflow to an Existing Machine Learning Project

See how to apply MLflow to an existing machine learning project.

Avkash Chauhan user avatar by
Avkash Chauhan
·
Jun. 16, 20 · Tutorial
Like (2)
Save
Tweet
Share
4.05K Views

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: 

https://github.com/keras-team/keras-io/blob/master/examples/structured_data/collaborative_filtering_movielens.py

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
Java
 




x


 
1
$ python collaborative_filtering_movielens.py


  • Create conda.yaml as below:
Java
 




xxxxxxxxxx
1
12


 
1
name: tf_keras_recom_example
2
channels:
3
 — defaults
4
 — anaconda
5
 — conda-forge
6
dependencies:
7
 — python=3.6
8
 — numpy=1.14.2
9
 — pandas
10
 — pip:
11
 — mlflow
12
 — tensorflow==2.0.0


  • Create MLProject as below:
Java
 




xxxxxxxxxx
1


 
1
name: movielens-recommendations-keras-tf2
2
conda_env: conda.yaml
3
entry_points:
4
    main:
5
        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
Java
 




xxxxxxxxxx
1


 
1
import mlflow.tensorflow
2
mlflow.tensorflow.autolog()


  • Comment matplotlib specific code in the project so plotting UI specific thread will not block the code execution.
Java
 




xxxxxxxxxx
1
10


 
1
# import matplotlib.pyplot as plt
2
....
3
....
4
# plt.plot(history.history[“loss”])
5
# plt.plot(history.history[“val_loss”])
6
# plt.title(“model loss”)
7
# plt.ylabel(“loss”)
8
# plt.xlabel(“epoch”)
9
# plt.legend([“train”, “test”], loc=”upper left”)
10
# plt.show()


That’s all. Now we will run the code in 2 separate terminal environments. 

Environment 1: Open the MLflow UI

Java
 




xxxxxxxxxx
1


 
1
$ 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:

Java
 




xxxxxxxxxx
1


 
1
$ mlflow run .


Once code start running the MLflow UI will show the progress as below:

Source Code for This Project:

https://github.com/Avkash/300seconds/tree/master/tf2-keras-recommendations

Project Walkthrough & Tutorial Video @ YouTube

https://youtu.be/RFtorfGDtJM

That’s all. Please stay safe and stay healthy. 

Machine learning

Published at DZone with permission of Avkash Chauhan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • 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)

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: