Run MLflow in Local or Remote Mode

This page provides two example MLflow workflows using scikit-learn linear regression models in a JupyterHub Notebook environment—one runs locally with the MLflow UI, and the other logs experiments to a remote MLflow tracking server.

Scenario 1: Local MLflow Tracking and UI Launch

Set up your environment

Install the required Python packages, if not installed.

Bash
Copy

Run a complete MLflow workflow

  1. Generate synthetic data using sklearn.datasets.make_regression.
  2. Split the data into training and test sets.
  3. Train a Linear Regression model using sklearn.linear_model.LinearRegression.
  4. Log model parameters, metrics, and the model to the local MLflow tracking server.
  5. Print the run ID and evaluation metrics for quick reference.
  6. Launch the MLflow UI to explore logged runs:
Bash
Copy

Access the UI at http://localhost:5000 to view experiment results, compare runs, and manage artifacts.

Key Code Snippet

Bash
Copy

Notes

  • Local tracking data stored in ./mlruns.
  • MLflow UI accessible at <MLflow_URL>.

Scenario 2: Remote MLflow Server with Custom Artifact Location

Set up your environment

Make sure MLflow and required dependencies are installed:

Bash
Copy

Run a remote MLflow workflow

  1. Set the tracking URI to point to your remote MLflow server.
Bash
Copy
  1. Create or use an existing experiment and define the artifact location (e.g., S3, NFS):
Bash
Copy
  1. Train a Linear Regression model using sklearn.linear_model.LinearRegression.
  2. Log parameters, metrics, and the model to the remote MLflow tracking server.
  3. Print run details such as run ID and metrics for quick access.

This setup allows centralized tracking, easier collaboration, and persistent storage of experiments.

Key Code Snippet

Bash
Copy

Notes

  • Artifacts stored at the configured remote location.
  • Update the tracking URI and artifact location as needed.

Summary

These examples show how to:

  • Run MLflow Tracking and UI locally
  • Log experiments to a remote MLflow server with custom artifact storage
  • Train, evaluate, and log models to ensure reproducibility

Use these templates to seamlessly integrate MLflow into your machine learning projects for effective experiment tracking and model management.

Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard
  Last updated