MLFlow 跟踪 ui 未在本地计算机(笔记本电脑)上显示实验

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

我是 mlflow 的初学者,正在尝试使用 Anaconda 3 在本地进行设置。 我在 anaconda 中创建了一个新环境,并在其中安装了 mlflow 和 sklearn。现在我正在使用 jupyter notebook 运行 我的 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)

'''

使用上面的代码,我成功地创建了 3 个不同的实验,因为我可以看到在我的本地目录中创建的文件夹,如下所示:

enter image description here

现在,我正在尝试 运行 mlflow ui 在我的 chrome 浏览器中使用 jupyter 终端,我可以打开 mlflow ui 但不能见和实验如下图:

enter image description here

你能帮我找出我哪里出错了吗?

你在哪里运行mlflow ui命令?

我认为如果您在参数中传递跟踪 ui 路径,它会起作用:

mlflow ui --backend-store-uri file:///Users/Swapnil/Documents/LocalPython/MLFLowDemo/mlrun