Chapter 06
Scenario 1: A single data scientist participating in an ML competition
NotebookPython 3.9.12 ('exp-tracking-env')12 cells
Scenario 1: A single data scientist participating in an ML competition
MLflow setup:
- Tracking server: no
- Backend store: local filesystem
- Artifacts store: local filesystem
The experiments can be explored locally by launching the MLflow UI.
In [ ]python · cell 2
python
import mlflowIn [ ]python · cell 3
python
print(f"tracking URI: '{mlflow.get_tracking_uri()}'")In [ ]python · cell 4
python
mlflow.search_experiments()Creating an experiment and logging a new run
In [ ]python · cell 6
python
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_iris
from sklearn.metrics import accuracy_score
mlflow.set_experiment("my-experiment-1")
with mlflow.start_run():
X, y = load_iris(return_X_y=True)
params = {"C": 0.1, "random_state": 42}
mlflow.log_params(params)
lr = LogisticRegression(**params).fit(X, y)
y_pred = lr.predict(X)
mlflow.log_metric("accuracy", accuracy_score(y, y_pred))
mlflow.sklearn.log_model(lr, artifact_path="models")
print(f"default artifacts URI: '{mlflow.get_artifact_uri()}'")In [ ]python · cell 7
python
mlflow.search_experiments()In [ ]python · cell 8
python
Interacting with the model registry
In [ ]python · cell 10
python
from mlflow.tracking import MlflowClient
client = MlflowClient()In [ ]python · cell 11
python
from mlflow.exceptions import MlflowException
try:
client.search_registered_models()
except MlflowException:
print("It's not possible to access the model registry :(")In [ ]python · cell 12
python
