Skip to main content
Version: 1.0.2


What is MLflow

MLflow is a platform to streamline machine learning development, including tracking experiments, packaging code into reproducible runs, and sharing and deploying models. MLflow offers a set of lightweight APIs that can be used with any existing machine learning application or library, for instance TensorFlow, PyTorch, XGBoost, etc. It runs wherever you currently run ML code, for example, in notebooks, standalone applications or the cloud. MLflow's current components are:

  • MLflow Tracking: An API to log parameters, code, and results in machine learning experiments and compare them using an interactive UI.
  • MLflow Projects: A code packaging format for reproducible runs using Conda and Docker, so you can share your ML code with others.
  • MLflow Models: A model packaging format and tools that let you easily deploy the same model from any ML library for both batch and real-time scoring. It supports platforms such as Docker, Apache Spark, Azure ML and AWS SageMaker.
  • MLflow Model Registry: A centralized model store, set of APIs, and UI, to collaboratively manage the full lifecycle of MLflow Models.


Install MLflow from PyPI via pip install mlflow

MLflow requires conda to be on the PATH for the projects feature.

Learn more about MLflow on their GitHub page.

Install Mlflow on Databricks

If you're using Databricks, install Mlflow with this command:

# run this so that Mlflow is installed on workers besides driver
%pip install mlflow

Install Mlflow on Synapse

To log model with Mlflow, you need to create an Azure Machine Learning workspace and link it with your Synapse workspace.

Create Azure Machine Learning Workspace

Follow this document to create AML workspace. You don't need to create compute instance and compute clusters.

Create an Azure ML Linked Service

  • In the Synapse workspace, go to Manage -> External connections -> Linked services, select + New
  • Select the workspace you want to log the model in and create the linked service. You need the name of the linked service to set up connection.

Auth Synapse Workspace

  • Go to the Azure Machine Learning workspace resource -> access control (IAM) -> Role assignment, select + Add, choose Add role assignment
  • Choose contributor, select next
  • In members page, choose Managed identity, select + select members. Under managed identity, choose Synapse workspace. Under Select, choose the workspace you run your experiment on. Click Select, Review + assign.

Use MLFlow in Synapse with Linked Service

Set up connection

#AML workspace authentication using linked service
from notebookutils.mssparkutils import azureML
linked_service_name = "YourLinkedServiceName"
ws = azureML.getWorkspace(linked_service_name)

#Set MLflow experiment. 
experiment_name = "synapse-mlflow-experiment"

Use MLFlow in Synapse without a Linked Service

Once you create an AML workspace, you can obtain the MLflow tracking URL directly. The AML start page is where you can locate the MLflow tracking URL.

You can set it tracking url with ```python mlflow.set_tracking_uri("your mlflow tracking url") ```

MLFlow API Reference



import mlflow
from import Featurize
from import *
from import ComputeModelStatistics

with mlflow.start_run():

feature_columns = ["Number of times pregnant","Plasma glucose concentration a 2 hours in an oral glucose tolerance test",
"Diastolic blood pressure (mm Hg)","Triceps skin fold thickness (mm)","2-Hour serum insulin (mu U/ml)",
"Body mass index (weight in kg/(height in m)^2)","Diabetes pedigree function","Age (years)"]
df = spark.createDataFrame([
], feature_columns+["labels"]).repartition(2)

featurize = (Featurize()

df_trans =

lightgbm_classifier = (LightGBMClassifier()

lightgbm_model =

# Use mlflow.spark.save_model to save the model to your path
mlflow.spark.save_model(lightgbm_model, "lightgbm_model")
# Use mlflow.spark.log_model to log the model if you have a connected mlflow service
mlflow.spark.log_model(lightgbm_model, "lightgbm_model")

# Use mlflow.pyfunc.load_model to load model back as PyFuncModel and apply predict
prediction = mlflow.pyfunc.load_model("lightgbm_model").predict(df_trans.toPandas())
prediction = list(map(str, prediction))
mlflow.log_param("prediction", ",".join(prediction))

# Use mlflow.spark.load_model to load model back as PipelineModel and apply transform
predictions = mlflow.spark.load_model("lightgbm_model").transform(df_trans)
metrics = ComputeModelStatistics(evaluationMetric="classification", labelCol='labels', scoredLabelsCol='prediction').transform(predictions).collect()
mlflow.log_metric("accuracy", metrics[0]['accuracy'])

Azure AI Services

import mlflow
from import *

with mlflow.start_run():

df = spark.createDataFrame([
("I am so happy today, its sunny!", "en-US"),
("I am frustrated by this rush hour traffic", "en-US"),
("The cognitive services on spark aint bad", "en-US"),
], ["text", "language"])

sentiment_model = (TextSentiment()


mlflow.spark.save_model(sentiment_model, "sentiment_model")
mlflow.spark.log_model(sentiment_model, "sentiment_model")

output_df = mlflow.spark.load_model("sentiment_model").transform(df)

# In order to call the predict function successfully you need to specify the
# outputCol name as `prediction`
prediction = mlflow.pyfunc.load_model("sentiment_model").predict(df.toPandas())
prediction = list(map(str, prediction))
mlflow.log_param("prediction", ",".join(prediction))