Basic Model Tracking¶
In this tutorial we'll show how to train a basic sci-kit learn
model and log it into MLflow. First we need a vasic dataset:
In [17]:
Copied!
import numpy as np
X = np.arange(100).reshape(100, 1)
y = X ** 2
import numpy as np
X = np.arange(100).reshape(100, 1)
y = X ** 2
Then select a simple linear regression model
In [ ]:
Copied!
from sklearn.linear_model import LinearRegression
model = LinearRegression()
from sklearn.linear_model import LinearRegression
model = LinearRegression()
Then we connect to the MLFlow server.
In [5]:
Copied!
import mlflow
mlflow.set_tracking_uri("http://localhost:5000")
import mlflow
mlflow.set_tracking_uri("http://localhost:5000")
Then we set the experiment.
In [6]:
Copied!
experiment = mlflow.set_experiment("test")
experiment = mlflow.set_experiment("test")
Then we'll use autolog
to simplify the process of logging the model and the metrics into MLflow,
In [7]:
Copied!
mlflow.sklearn.autolog()
mlflow.sklearn.autolog()
Finally train the model and automatically log the metrics and the model.
In [9]:
Copied!
experiment_id = experiment.experiment_id
with mlflow.start_run(experiment_id=experiment_id):
model.fit(X, y)
experiment_id = experiment.experiment_id
with mlflow.start_run(experiment_id=experiment_id):
model.fit(X, y)
2024/10/12 17:59:03 INFO mlflow.tracking._tracking_service.client: 🏃 View run bittersweet-koi-963 at: http://localhost:5000/#/experiments/406653565916109575/runs/ef588dbfe5bd487abc3ca25eb5151e6f. 2024/10/12 17:59:03 INFO mlflow.tracking._tracking_service.client: 🧪 View experiment at: http://localhost:5000/#/experiments/406653565916109575.