Get startedGet started for free

Saving and loading a model

With the Model API, models can be shared between developers who may not have access to the same MLflow Tracking server by using a local filesystem.

In this exercise, you will train a new LinearRegression model from an existing one using the Unicorn dataset. First, you will load an existing model from the local filesystem. Then you will train a new model from the existing model and save it back to the local filesystem.

The existing model has been saved to the local filesystem in a directory called "lr_local_v1". The mlflow module will be imported.

This exercise is part of the course

Introduction to MLflow

View Course

Exercise instructions

  • Load the model from the local filesystem directory "lr_local_v1" using scikit-learn library from the MLflow module.
  • Using the scikit-learn library from the mlflow module, save the model locally to a directory called "lr_local_v2".

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Load model from local filesystem
model = ____.____.____("____")

# Training Data
X = df[["R&D Spend", "Administration", "Marketing Spend", "State"]]
y = df[["Profit"]]
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.7,random_state=0)
# Train Model
model.fit(X_train, y_train)

# Save model to local filesystem
____.____.____(____, "____")
Edit and Run Code