MLFlow tracking ui not showing experiments on local machine (laptop)

Question:

I am a beginner in mlflow and was trying to set it up locally using Anaconda 3.
I have created a new environment in anaconda and install mlflow and sklearn in it. Now I am using jupyter notebook to run my sample code for mlflow.

”’

import os
import warnings
import sys

import pandas as pd
import numpy as np
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
from sklearn.model_selection import train_test_split
from sklearn.linear_model import ElasticNet
from urllib.parse import urlparse
import mlflow
import mlflow.sklearn

import logging

logging.basicConfig(level=logging.WARN)
logger = logging.getLogger(__name__)

warnings.filterwarnings("ignore")
np.random.seed(40)


mlflow.set_tracking_uri("file:///Users/Swapnil/Documents/LocalPython/MLFLowDemo/mlrun")

mlflow.get_tracking_uri()

mlflow.get_experiment

#experiment_id = mlflow.create_experiment("Mlflow_demo")
experiment_id = mlflow.create_experiment("Demo3")
experiment = mlflow.get_experiment(experiment_id)
print("Name: {}".format(experiment.name))
print("Experiment_id: {}".format(experiment.experiment_id))
print("Artifact Location: {}".format(experiment.artifact_location))
print("Tags: {}".format(experiment.tags))
print("Lifecycle_stage: {}".format(experiment.lifecycle_stage))

mlflow.set_experiment("Demo3")

def eval_metrics(actual, pred):
    rmse = np.sqrt(mean_squared_error(actual, pred))
    mae = mean_absolute_error(actual, pred)
    r2 = r2_score(actual, pred)
    return rmse, mae, r2

# Read the wine-quality csv file from the URL
csv_url =
    'http://archive.ics.uci.edu/ml/machine-learning-databases/wine-quality/winequality-red.csv'
try:
    data = pd.read_csv(csv_url, sep=';')
except Exception as e:
    logger.exception(
        "Unable to download training & test CSV, check your internet connection. Error: %s", e)

data.head(2)


def train_model(data, alpha, l1_ratio):
    
    # Split the data into training and test sets. (0.75, 0.25) split.
    train, test = train_test_split(data)

    # The predicted column is "quality" which is a scalar from [3, 9]
    train_x = train.drop(["quality"], axis=1)
    test_x = test.drop(["quality"], axis=1)
    train_y = train[["quality"]]
    test_y = test[["quality"]]

    # Set default values if no alpha is provided
    alpha = alpha
    l1_ratio = l1_ratio


    # Execute ElasticNet
    lr = ElasticNet(alpha=alpha, l1_ratio=l1_ratio, random_state=42)
    lr.fit(train_x, train_y)

    # Evaluate Metrics
    predicted_qualities = lr.predict(test_x)
    (rmse, mae, r2) = eval_metrics(test_y, predicted_qualities)

    # Print out metrics
    print("Elasticnet model (alpha=%f, l1_ratio=%f):" % (alpha, l1_ratio))
    print("  RMSE: %s" % rmse)
    print("  MAE: %s" % mae)
    print("  R2: %s" % r2)
    
    # Log parameter, metrics, and model to MLflow
    with mlflow.start_run(experiment_id = experiment_id):
        mlflow.log_param("alpha", alpha)
        mlflow.log_param("l1_ratio", l1_ratio)
        mlflow.log_metric("rmse", rmse)
        mlflow.log_metric("r2", r2)
        mlflow.log_metric("mae", mae)
        mlflow.sklearn.log_model(lr, "model")
        

train_model(data, 0.5, 0.5)

train_model(data, 0.5, 0.3)

train_model(data, 0.4, 0.3)

”’

using above code, I am successfully able to create 3 different experiment as I can see the folders created in my local directory as shown below:

enter image description here

Now, I am trying to run the mlflow ui using the jupyter terminal in my chrome browser and I am able to open the mlflow ui but cannot see and experiments as shown below:

enter image description here

Could you help me in finding where I am going wrong?

Asked By: Swapnil

||

Answers:

Where do you run mlflow ui command?

I think if you pass tracking ui path in the arguments, it would work:

mlflow ui --backend-store-uri file:///Users/Swapnil/Documents/LocalPython/MLFLowDemo/mlrun
Answered By: Matin Zivdar

Came across the same problem. To fix it, I copied all the code to a python file in vscode and ran mlflow ui (after binding the path), and I was able to see my experiments then. Haven’t been able to solve it with jupyter yet

vsc screenshot of running mlflow ui

screenshot of mlflow with recent experiment

Answered By: Nimra Ahmed
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.