【问题标题】:get the run id for an mlflow experiment with the name?获取名称为 mlflow 实验的运行 ID?
【发布时间】:2020-12-16 02:45:27
【问题描述】:

我目前在 mlflow 中创建了一个实验,并在该实验中创建了多次运行。

from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error
import mlflow

experiment_name="experiment-1"
mlflow.set_experiment(experiment_name)

no_of_trees=[100,200,300]
depths=[2,3,4]
for trees in no_of_trees:
    for depth in depths:
        with mlflow.start_run() as run:
            model=RandomForestRegressor(n_estimators=trees, criterion='mse',max_depth=depth)
            model.fit(x_train, y_train)
            predictions=model.predict(x_cv)
            mlflow.log_metric('rmse',mean_squared_error(y_cv, predictions))

创建运行后,我想为此实验获得最佳 run_id。目前,我可以通过查看 mlflow 的 UI 来获得最佳运行,但我们如何才能正确地执行程序呢?

【问题讨论】:

    标签: python mlflow


    【解决方案1】:

    我们可以从实验名称中获取实验 ID,我们可以使用 python API 来获得最佳运行。

    experiment_name = "experiment-1"
    current_experiment=dict(mlflow.get_experiment_by_name(experiment_name))
    experiment_id=current_experiment['experiment_id']
    

    通过使用实验 ID,我们可以获得所有运行,我们可以根据如下指标对它们进行排序。在下面的代码中,rmse 是我的指标名称(因此根据指标名称,您可能会有所不同)

    df = mlflow.search_runs([experiment_id], order_by=["metrics.rmse DESC"])
    best_run_id = df.loc[0,'run_id']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-17
      • 2021-04-23
      • 1970-01-01
      • 2020-03-19
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      • 2021-05-15
      相关资源
      最近更新 更多