Exercise

Logging and loading a model

The Model API provides a way to interact with our models by logging and loading them directly from MLflow Tracking in a standardized manner. Being able to interact with models is crucial during the ML lifecycle for the Model Engineering and Model Evaluation steps.

In this exercise you will create a Linear Regression model from scikit-learn using the Unicorn dataset. This model will be logged to MLflow Tracking and then loaded using the run_id used to log the artifact.

First, you will log the model using the scikit-learn library from the MLflow module. Then you will load the model from MLflow Tracking using the run_id.

The model will be trained and have the name lr_model.

lr_model = LinearRegression()
lr_model.fit(X_train, y_train)

The mlflow module will be imported.

Instructions

100 XP
  • Log the model to MLflow Tracking under the artifact path of "lr_tracking".
  • Create a variable called run that is set to the last run.
  • Create another variable called run_id that is set to the run_id of the run variable.
  • Load the model using the run_id and the artifact path used to log the model.