[英]get the run id for an mlflow experiment with the name?
我目前在 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 獲得最佳運行效果,但我們如何才能正確運行該程序?
我們可以從實驗名稱中獲取實驗 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']
使用filter_string
按名稱或其他屬性直接搜索:
mlflow.search_runs(filter_string="run_name='CV_M1_A1_regional'")['run_id'] #539aa3507ba54ebf86e64c7c9766fcee
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.