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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Beyond Code Coverage: A Risk-Driven Revolution in Software Testing With Machine Learning
  • Accelerating AI Inference With TensorRT
  • AI's Dilemma: When to Retrain and When to Unlearn?
  • Getting Started With GenAI on BigQuery: A Step-by-Step Guide

Trending

  • AWS to Azure Migration: A Cloudy Journey of Challenges and Triumphs
  • How Trustworthy Is Big Data?
  • Beyond Code Coverage: A Risk-Driven Revolution in Software Testing With Machine Learning
  • FIPS 140-3: The Security Standard That Protects Our Federal Data
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. How to Setup/Install MLFlow and Get Started

How to Setup/Install MLFlow and Get Started

In this post, you will learn about how to setup/install MLFlow right from your Jupyter Notebook and get started tracking your machine learning projects.

By 
Ajitesh Kumar user avatar
Ajitesh Kumar
·
Oct. 29, 20 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
16.0K Views

Join the DZone community and get the full member experience.

Join For Free

In this post, you will learn about how to setup/install MLFlow right from your Jupyter Notebook and get started tracking your machine learning projects. This would prove to be very helpful if you are running an enterprise-wide AI practice where you have a bunch of data scientists working on different ML projects. MLFlow will help you track the score of different experiments related to different ML projects.

Install MLFlow Using Jupyter Notebook

In order to install/set up MLFlow and do a quick POC, you could get started right from within your Jupyter notebook. Here are the commands to get set up. MLFlow could be installed with the simple command: pip install mlflow. Within Jupyter notebook, this is what you would do:

Java
 




x


 
1
#
2
# Install MLFLow using PIP Install
3
#
4
!pip install mlflow
5
#
6
# Check whether MLFlow installed by accessing its version
7
#
8
!mlflow --version



Executing the above commands would set up MLFlow and print its version. It printed this for me: mlflow, version 1.11.0

The next step is to start MLFlow UI. Here is the command to get started with MLFlow UI from within Jupyter Notebook

Java
 




xxxxxxxxxx
1


 
1
#
2
# Mlflow UI
3
#
4
!mlflow ui



You could as well execute the command, mlflow ui, in the command prompt and it would start the server at URL such as http://127.0.0.1:5000/. This is how the MLFlow UI would look:

Fig 1. MLFlow UI Application


The next step is to run some experiments in form of training a model. The goal is to track the model runs in MLFlow UI.

Run Experiments/Train Model and Track Using MLFlow UI

In order to get started with training the model and tracking the model scores/experiment outcomes using MLFlow, I would suggest you take a look at this POC.

Download the MLFlow sample code from this MLFlow GitHub page: https://github.com/mlflow/mlflow. You can train a simple logistic regression model using the code given below. This can be found in the following folder in the downloaded code (examples/sklearn_logistic_regression/train.py).

Java
 




xxxxxxxxxx
1
16


 
1
import numpy as np
2
from sklearn.linear_model import LogisticRegression
3

           
4
import mlflow
5
import mlflow.sklearn
6

           
7
if __name__ == "__main__":
8
    X = np.array([-2, -1, 0, 1, 2, 1]).reshape(-1, 1)
9
    y = np.array([0, 0, 1, 1, 1, 0])
10
    lr = LogisticRegression()
11
    lr.fit(X, y)
12
    score = lr.score(X, y)
13
    print("Score: %s" % score)
14
    mlflow.log_metric("score", score)
15
    mlflow.sklearn.log_model(lr, "model")
16
    print("Model saved in run %s" % mlflow.active_run().info.run_uuid)



All this is required to be done is to add the below code to your machine learning model training code and execute with Python. This would make sure that MLflow runs can be recorded to local file. You could as well record the MLFlow runs on remote server. To log ML project runs remotely, you will need to set the MLFLOW_TRACKING_URI environment variable to the tracking server's URI. The code below is executed from within Jupyter notebook.

Java
 




xxxxxxxxxx
1


 
1
!python /Users/apple/Downloads/mlflow-master/examples/sklearn_logistic_regression/train.py



This will output the following shown as a screenshot:

Fig 2. MLFlow sample run output


The above run could now be accessed in MLFlow UI.

Fig 3. Tracking MLFLow project


You could learn more about MLFlow on MLFLow concept page.

Conclusions

Here is the summary of what you learned in this post in relation to setting up / installing MLFlow and getting started:

  • MLFlow can be installed simply with a command such as pip install mlflow.
  • MLFlow UI can be started using a command such as mlflow ui
  • Machine learning model training logs can be written by using MLFlow APIs/methods in the model training code.
  • MLflow runs can be recorded to local files, to a SQLAlchemy compatible database, or remotely to a tracking server.
Machine learning jupyter notebook

Published at DZone with permission of Ajitesh Kumar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Beyond Code Coverage: A Risk-Driven Revolution in Software Testing With Machine Learning
  • Accelerating AI Inference With TensorRT
  • AI's Dilemma: When to Retrain and When to Unlearn?
  • Getting Started With GenAI on BigQuery: A Step-by-Step Guide

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!