python - 如何为完成的 MLflow 运行添加更多指标?
问题描述
MLflow 运行完成后,外部脚本可以使用 pythonmlflow
客户端和mlflow.get_run(run_id)
方法访问其参数和指标,但Run
返回的对象get_run
似乎是只读的。
具体来说,.log_param
.log_metric
或.log_artifact
不能用于返回的对象get_run
,引发如下错误:
AttributeError: 'Run' object has no attribute 'log_param'
如果我们尝试在 上运行任何.log_*
方法mlflow
,它会将它们记录到具有Default
实验中自动生成的运行 ID 的新运行中。
例子:
final_model_mlflow_run = mlflow.get_run(final_model_mlflow_run_id)
with mlflow.ActiveRun(run=final_model_mlflow_run) as myrun:
# this read operation uses correct run
run_id = myrun.info.run_id
print(run_id)
# this write operation writes to a new run
# (with auto-generated random run ID)
# in the "Default" experiment (with exp. ID of 0)
mlflow.log_param("test3", "This is a test")
请注意,无论状态如何,上述问题都存在Run
(.info.status
可以是“FINISHED”或“RUNNING”,没有任何区别)。
我想知道这种只读行为是否是设计使然(鉴于不可变建模运行提高了实验的可重复性)?我可以理解这一点,但如果所有事情都必须在一个单一的整体中完成,比如with mlflow.start_run()
上下文......
解决方案
正如Hans Bambel向我指出的那样,正如这里 mlflow.start_run
记录的那样(与 相比mlflow.ActiveRun
)接受run_id
现有运行的参数。
这是一个经过测试可在 v1.13 到 v1.19 中工作的示例 - 正如您所看到的,甚至可以覆盖现有指标来纠正错误:
with mlflow.start_run(run_id=final_model_mlflow_run_id):
# print(mlflow.active_run().info)
mlflow.log_param("start_run_test", "This is a test")
mlflow.log_metric("start_run_test", 1.23)
mlflow.log_metric("start_run_test", 1.33)
mlflow.log_artifact("/home/jovyan/_tmp/formula-features-20201103.json", "start_run_test")
推荐阅读
- c# - C# 将对象分配给对象列表
- python-3.x - 按 int 值过滤数据帧
- ios - 如何在swift中使用api公共管理器类删除传递数组的json解析错误作为参数?
- azure-cognitive-services - 上传 Business Central Base App.xlf 导致“无法提取上传文件的内容”。
- sql - 当 Sqoop 作业在 50% 数据加载后失败时会发生什么?
- javascript - 将几何图形插入 PostGIS
- c++ - C6001:使用未初始化的内存“str[i]”
- flask - 登录时 Flask Fetch 请求 502 bad gateway 错误
- javascript - 在函数调用上打开模态
- google-chrome - Windows 身份验证在 Chrome 上无法正常工作