我是 MLflow 的新手。我试图在 Jupyter 中使用它。作为快速入门的一部分,我运行了以下代码:
import os
from mlflow import log_metric, log_param, log_artifact
if __name__ == "__main__":
# Log a parameter (key-value pair)
log_param("param1", 5)
# Log a metric; metrics can be updated throughout the run
log_metric("foo", 1)
log_metric("foo", 2)
log_metric("foo", 3)
# Log an artifact (output file)
with open("output.txt", "w") as f:
f.write("Hello world!")
log_artifact("output.txt")
Run Code Online (Sandbox Code Playgroud)
运行没有任何问题。但是,当我输入 时mlflow ui,出现错误:语法无效。我可能做错了什么?
MLFlow 快速入门中的文档 假定您将此代码保存为 Python.py脚本并在终端(或其他命令行解释器)中运行它。\n当您在终端或 Jupyter 中运行脚本时,mlruns会自动创建一个名为的文件夹。
\n\n\n“默认情况下,无论您在何处运行程序,跟踪 API 都会将数据写入到 mlruns 目录中的文件中。然后您可以运行 MLflow\xe2\x80\x99s Tracking UI”
\n
如果您想从笔记本运行 MLflow\xe2\x80\x99s 跟踪 UI,您应该编写!mlflow ui而不是mlflow ui. 您会收到语法错误,因为它不是有效的 Python 语法。!mlflow ui如果您从笔记本运行,您仍然可以在http://localhost:5000查看跟踪 UI 。但是,在这种情况下,您将无法运行任何其他单元,因为当前单元仍在运行。
您应该更好地使用终端,并在包含笔记本和 mlruns 文件夹的mlflow ui 同一当前工作目录中运行代码。