mlflow-quick-start-python(Python)

Loading...

MLflow example (Python)

With MLflow's autologging capabilities, a single line of code automatically logs the resulting model, the parameters used to create the model, and a model score. MLflow autologging is available for several widely used machine learning packages. This notebook creates a Random Forest model on a simple dataset and uses the the MLflow autolog() function to log information generated by the run.

For details about what information is logged with autolog(), refer to the MLflow documentation.

Setup

  • If you are using a cluster running Databricks Runtime, you must install the mlflow library from PyPI. See Cmd 3.
  • If you are using a cluster running Databricks Runtime ML, the mlflow library is already installed.

Install the mlflow library. This is required for Databricks Runtime clusters only. If you are using a cluster running Databricks Runtime ML, skip to Cmd 4.

Import the required libraries.

Import the dataset from scikit-learn and create the training and test datasets.

Create a random forest model and log parameters, metrics, and the model using mlflow.sklearn.autolog().

To view the results, click the Experiments icon in the right sidebar. This sidebar displays the parameters and metrics for each run of this notebook.

Click the name of the run to open the Runs page in a new tab. This page shows all of the information that was logged from the run. Select the Artifacts tab to find the logged model and plot.

For more information, see "MLflow experiments" (AWS|Azure|GCP).