Skip to content

Commit 023f756

Browse files
authored
Update how-to-track-experiments-mlflow.md
1 parent 6978c25 commit 023f756

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

articles/machine-learning/how-to-track-experiments-mlflow.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ See [Support matrix for querying runs and experiments in Azure Machine Learning]
3232

3333
[!INCLUDE [mlflow-prereqs](../../includes/machine-learning-mlflow-prereqs.md)]
3434

35+
## Query experiments
36+
37+
Use MLflow to search for experiments inside of your workspace.
38+
3539
## Getting all the experiments
3640

37-
You can get all the active experiments in the workspace using MLFlow:
41+
You can get all the active experiments in the workspace using MLflow:
3842

3943
```python
4044
experiments = mlflow.search_experiments()
@@ -43,9 +47,9 @@ for exp in experiments:
4347
```
4448

4549
> [!NOTE]
46-
> __MLflow 2.0 advisory:__ In legacy versions of MLflow (<2.0) use method `list_experiments` instead.
50+
> In legacy versions of MLflow (<2.0) use method `mlflow.list_experiments()` instead.
4751
48-
If you want to retrieve archived experiments too, then include the option `ViewType.ALL` in the `view_type` argument. The following sample shows how:
52+
If you want to retrieve archived experiments too, then include the parameter `view_type=ViewType.ALL`. The following sample shows how:
4953

5054
```python
5155
from mlflow.entities import ViewType
@@ -55,26 +59,26 @@ for exp in experiments:
5559
print(exp.name)
5660
```
5761

58-
## Search experiments
62+
### Getting a specific experiment
5963

60-
The `search_experiments()` method available since Mlflow 2.0 allows searching experiment matching a criteria using `filter_string`. The following query retrieves three experiments with different IDs.
64+
Details about a specific experiment can be retrieved using the `get_experiment_by_name` method:
6165

6266
```python
63-
mlflow.search_experiments(filter_string="experiment_id IN (
64-
'CDEFG-1234-5678-90AB', '1234-5678-90AB-CDEFG', '5678-1234-90AB-CDEFG')"
65-
)
67+
exp = mlflow.get_experiment_by_name(experiment_name)
68+
print(exp)
6669
```
6770

68-
## Getting a specific experiment
71+
### Searching experiments
6972

70-
Details about a specific experiment can be retrieved using the `get_experiment_by_name` method:
73+
The `search_experiments()` method available since Mlflow 2.0 allows searching experiment matching a criteria using `filter_string`. The following query retrieves three experiments with different IDs.
7174

7275
```python
73-
exp = mlflow.get_experiment_by_name(experiment_name)
74-
print(exp)
76+
mlflow.search_experiments(filter_string="experiment_id IN (
77+
'CDEFG-1234-5678-90AB', '1234-5678-90AB-CDEFG', '5678-1234-90AB-CDEFG')"
78+
)
7579
```
7680

77-
## Query runs inside an experiment
81+
## Query and search runs inside an experiment
7882

7983
MLflow allows searching runs inside of any experiment, including multiple experiments at the same time. By default, MLflow returns the data in Pandas `Dataframe` format, which makes it handy when doing further processing our analysis of the runs. Returned data includes columns with:
8084

@@ -131,13 +135,13 @@ You can also look for a run with a specific combination in the hyperparameters u
131135
```python
132136
mlflow.search_runs(experiment_ids=[ "1234-5678-90AB-CDEFG" ],
133137
filter_string="params.num_boost_round='100'")
134-
```
138+
```
135139

136-
Specific run field can also be indicated. Fields do not need a qualifier like `params`, `metrics` or `attributes`. The following search query for runs with specific IDs.
140+
You can also use the qualifier `attributes` to query for specific attributes of the run like `creation_time` or `run_id`. The following example conditions the query to return only specific runs:
137141

138142
```python
139143
mlflow.search_runs(experiment_ids=[ "1234-5678-90AB-CDEFG" ],
140-
filter_string="run_id IN ('CDEFG-1234-5678-90AB', '1234-5678-90AB-CDEFG', '5678-1234-90AB-CDEFG')")
144+
filter_string="attributes.run_id IN ('1234-5678-90AB-CDEFG', '5678-1234-90AB-CDEFG')")
141145
```
142146

143147
### Filter runs by status
@@ -163,6 +167,16 @@ The following example shows all the completed runs:
163167
runs = mlflow.search_runs(experiment_ids=[ "1234-5678-90AB-CDEFG" ])
164168
runs[runs.status == "FINISHED"]
165169
```
170+
171+
### Searching runs accross experiments
172+
173+
The method `search_runs` require you to indicate the experiment name or ID you want to search runs in. However, if you want to query runs across multiple experiments, you can indicate the argument `search_all_experiments=True` to expand the search.
174+
175+
```python
176+
mlflow.search_runs(filter_string="params.num_boost_round='100'", search_all_experiments=True)
177+
```
178+
179+
Notice that if `search_all_experiments` is not indicated and no experiment ID or name is indicated, the search is performed in the current active experiment (the one indicated in `mlflow.set_experiment()` method).
166180

167181
## Getting metrics, parameters, artifacts and models
168182

@@ -222,7 +236,7 @@ file_path = mlflow.artifacts.download_artifacts(
222236
```
223237

224238
> [!NOTE]
225-
> __MLflow 2.0 advisory:__ In legacy versions of MLflow (<2.0), use the method `MlflowClient.download_artifacts()` instead.
239+
> In legacy versions of MLflow (<2.0), use the method `MlflowClient.download_artifacts()` instead.
226240
227241
### Getting models from a run
228242

0 commit comments

Comments
 (0)