1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to MLflow

Exercise

Custom scikit-learn model

In this exercise you are going to create a custom model using MLflow's pyfunc flavor. Using the insurance_charges dataset, the labels must be changed from female to 0 and male to 1 for classification during training. When using the model, the strings of female or male must be returned instead of 0 or 1.

The custom model is a Classification model based on LogisticRegression and will use a Class called CustomPredict. The CustomPredict adds an additional step in the the predict method that sets your labels of 0 and 1 back to female and male when the model receives input. You will be using pyfunc flavor for logging and loading your model.

Our insurance_charges dataset will be preprocessed and model will be trained using:

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

The MLflow module will be imported.

Instructions

100 XP
  • Use MLflow's pyfunc flavor to log the custom model.
  • Set pyfunc python_model argument to use the Custom Class CustomPredict().
  • Load the custom model using pyfunc.