MLOps and trustworthy AI tutorial: Build and deploy a model

This tutorial is the first in a series of two tutorials. Take this tutorial to build, deploy, and track a model with the MLOps and trustworthy AI use case of the data fabric trial. Your goal is to train a model to predict which applicants qualify for mortgages and then deploy the model for evaluation. You must also set up tracking for the model to document the model history and generate an explanation for its performance.

The following animated image provides a quick preview of what you’ll accomplish by the end of the second tutorial where you will use Watson OpenScale to configure and evaluate monitors for the deployed model to ensure that the model is accurate and treating all applicants fairly. Right-click the image and open it in a new tab to view a larger image.

Screenshots of the tutorial

The story for the tutorial is that Golden Bank wants to expand its business by offering low-rate mortgage renewals for online applications. Online applications expand the bank’s customer reach and reduce the bank’s application processing costs. As a data scientist at Golden Bank, you must create a mortgage approval model that avoids unanticipated risk and treats all applicants fairly. You will run a Jupyter Notebook to build a model and automatically capture metadata that tracks the model in an AI Factsheet.

In this tutorial, you will complete these tasks:

  1. Set up tracking for your model.
  2. Create a model entry in the model inventory.
  3. Run the notebook to create the model.
  4. View the model's factsheet and associate it with a model entry.
  5. Deploy the model.

If you need help with this tutorial, you can ask a question or find an answer in the Cloud Pak for Data Community discussion forum.

Tip: For the optimal experience completing this tutorial, open Cloud Pak for Data in one browser window, and keep this tutorial page open in another browser window to switch easily between the two applications. Consider arranging the two browser windows side-by-side to make it easier to follow along.

Side-by-side tutorial and UI

Preview the tutorial

Watch Video Watch this video to preview the steps in this tutorial. There might be slight differences in the user interface shown in the video. The video is intended to be a companion to the written tutorial.

This video provides a visual method as an alternative to following the written steps in this documentation.

Prerequisites

The following prerequisites are required to complete this tutorial.

Access type Description Documentation
Services - Watson Studio
- Watson Machine Learning
- Watson Knowledge Catalog
- Watson OpenScale
- Db2
- Watson Studio
- Watson Machine Learning
- Watson Knowledge Catalog
- Watson OpenScale
- Db2
Role Data Scientist - Predefined roles and permissions
- Manage roles
Permissions - Manage information assets
- Access advanced governance
- Administer platform
- Predefined roles and permissions
- Manage roles
Additional access - Editor access to Default Catalog
- Admin access to the Watson OpenScale instance
- Completed setup for Watson OpenScale
- Add collaborators
- Managing users for Watson OpenScale the service
- Automated setup
Additional configuration Disable Enforce the exclusive use of secrets Require users to use secrets for credentials

Follow these steps to verify your roles and permissions. If your Cloud Pak for Data account does not meet all of the prerequisites, contact your administrator.

  1. Click your profile image in the toolbar.

  2. Click Profile and settings.

  3. Select the Roles tab.

The permissions that are associated with your role (or roles) are listed in the Enabled permissions column. If you are a member of any user groups, you inherit the roles that are assigned to that group. These roles are also displayed on the Roles tab, and the group from which you inherit the role is specified in the User groups column. (If the User groups column shows a dash, that means the role is assigned directly to you.)
Roles and permissions

Create the sample project

If you did not already create the sample project for this tutorial, follow these steps:

  1. Download the MLOps-and-Trustworthy-AI.zip file.

  2. From the Cloud Pak for Data navigation menu Navigation menu, choose Projects > All projects.

  3. On the Projects page, click New project.

  4. Select Create a project from a file.

  5. Upload the previously downloaded ZIP file.

  6. On the Create a project page, type the project name and optional description for the project.

    MLOps and Trustworthy AI
    
  7. Click Create.

  8. Click View new project to verify that the project and assets were created successfully.

  9. Click the Assets tab, to view the project's assets.

Checkpoint Check your progress

The following image shows the sample project. You are now ready to start the tutorial.

Sample project

Tip: If you encounter a guided tour while completing this tutorial in the Cloud Pak for Data user interface, click Maybe later.

Task 1: Set up tracking for your model

You track models by adding model entries to a catalog. Follow these steps to see whether you have Editor access to the Default Catalog:

  1. From the Cloud Pak for Data navigation menu Navigation menu, choose Catalogs > All catalogs.

  2. On the Catalogs page, open the Default Catalog. If you do not see the Default Catalog on the Catalogs page, then contact your administrator to request Editor access to the Default Catalog.

  3. Click the Access control tab.

  4. Verify that your access is Editor or higher. If your access is Viewer, then contact your administrator to request Editor access to the Default Catalog.

Checkpoint Check your progress

The following image shows your catalog. You are now ready to create the model entry that is stored in the catalog.

Mortgage Approval Catalog

Task 2: Create the model entry in the model inventory

For this type of project, it is best to create the model entry when a project commences. A model entry can reference multiple machine learning models that you can use to solve business problems. Then, data engineers and model evaluators can add models to the model entry and track the model as it progresses through its lifecycle. Follow these steps to create the model entry:

Tip: If this occasion is your first time accessing the Model inventory, you see a guided tour asking if you want to set up model governance. For now, click Maybe later.
  1. From the Cloud Pak for Data navigation menu Navigation menu, choose Catalogs > Model inventory.

  2. Click New model entry.

  3. For the Model entry name, copy and paste the name exactly as shown with no leading or trailing spaces:

    Mortgage Approval Model Entry
    
  4. For the Description, type:

    This model entry is for the Mortgage approval use case at Golden Bank
    
  5. If you have more than one catalog, then you see a Catalog field. Select Default Catalog.

  6. Click Save.

Checkpoint Check your progress

The following image shows your model entry. The model entry is now ready for data engineers and model evaluators to add models and track models as they progress through their lifecycle. The next task is to run the notebook to create the model.

Mortgage Approval Model Entry

Task 3: Run the notebook to create the model

Next, run the first notebook included in the sample project to:

Follow these steps to run the notebook included in the sample project. Take some time to read through the comments in the notebook, which explain the code in each cell.

  1. From the Cloud Pak for Data navigation menu Navigation menu, choose Projects > All projects.

  2. Click the MLOps and trustworthy AI project name.

  3. Click the Assets tab, and then navigate to Source code > Notebook.
    Left navigation

  1. Open the 1-model-training-with-factsheets notebook.

  2. Since the notebook is in read-only mode, click the Edit Edit icon icon to place the notebook in edit mode.

  3. To run all of the cells in the notebook, click Cell > Run All. Alternatively, you can run the notebook cell by cell if you want to explore each cell and its output.

  4. The first cell requires your input.

    1. At the Enter host name prompt, type your Cloud Pak for Data hostname beginning with https://, and press Enter.

    2. At the Username prompt, type your Cloud Pak for Data username, and press Enter.

    3. At the Password prompt, type your Cloud Pak for Data password, and press Enter.

  5. The notebook takes 1 - 3 minutes to complete. You can monitor the progress cell by cell, noticing the asterisk "In [*]" changing to a number, for example, "In [1]".

  6. If you encounter any errors during the notebook run, try these tips:

    • Click Kernel > Restart & Clear Output to restart the kernel, and then run the notebook again.
    • Verify that you created the model entry by copying and pasting the specified artifact name exactly with no leading or trailing spaces.

Checkpoint Check your progress

The following image shows the notebook when the run is complete. The notebook saved the model in the project, so you are now ready to view and add it to the model inventory.

Notebook run complete

Task 4: View the model's factsheet and associate it with a model entry

After running all the cells in notebook, follow these steps to view the model's factsheet in the project and then associate that model with a model entry in the model inventory:

  1. Click the MLOps and trustworthy AI project name in the navigation trail.
    Navigation trail

  2. Click the Assets tab, and then navigate to Models > Model.

  3. Click the Mortgage Approval Prediction Model asset name that you previously created to open the model.

  4. Review the AI Factsheet for your model. AI Factsheets capture model metadata across the model development lifecycle, facilitating subsequent enterprise validation or external regulation. AI Factsheets enables model validators and approvers to get an accurate, always up-to-date view of the model lifecycle details.
    In the last task, you ran a notebook containing the AI Factsheets Python client code in the notebook that captured training metadata. Scroll to the Training metrics and Training tags sections to review the captured training metadata.
    Checkpoint The following image shows the AI Factsheet for the model:

    Model's AI Factsheet

  5. Scroll up on the model page, and click Track this model.

    1. Select Select an existing model entry.

    2. From the list of model entries, select Mortgage Approval Model Entry.

    3. Click Track.

  6. Back on the model page, click Open in model inventory.

  7. On the model entry page, click the Asset tab.

  8. Under Model tracking, you can see that AI Factsheets track models through their lifecycle. This model is still in the Develop stage as it has not been deployed yet.

Checkpoint Check your progress

The following image shows the model entry with the model in the Develop phase. Now that you reviewed metadata such as the training data source, training metrics, and input schema that was captured in the AI Factsheet, you are ready to deploy the model.

Model entry in Develop phase

Task 5: Deploy the model

Before you can deploy the model, you need to promote the model to a new deployment space. Deployment spaces help you to organize supporting resources such as input data and environments; deploy models or functions to generate predictions or solutions; and view or edit deployment details.

Promote the model to a deployment space

Follow these steps to promote the model to a new deployment space:

  1. From the model entry, under the Develop phase, click Mortgage Approval Prediction Model.

  2. Click Open in project to open the model in the MLOps and trustworthy AI project.

  3. On the model page, click Promote to deployment space.

  4. For the Target space, select Create a new deployment space.

    1. For the deployment space name, copy and paste the name exactly as shown with no leading or trailing spaces:

      Golden Bank Preproduction Space
      
    2. Click Create.

    3. Click Close.

  5. For the Target space, ensure that Golden Bank Preproduction Space is selected.

  6. Check the Go to model in the space after promoting it option.

  7. Click Promote.

Checkpoint Check your progress

The following image shows the model in the deployment space. You are now ready to create a model deployment.

Model in deployment space

Create an online deployment for the model

Follow these steps to create an online deployment for your model:

  1. When the deployment space opens, click New deployment.

    1. For the Deployment type, select Online.

    2. For the Name, copy and paste the deployment name exactly as shown with no leading or trailing spaces:

      Mortgage Approval Model Deployment
      
    3. For the Serving name, you can specify a descriptive name to use in place of the deployment ID that will help you to identify this deployment quickly. Copy and paste the serving name with no leading or trailing spaces. The name is validated to be unique per region. If this serving name exists, then add a number (or any unique character) to the end of the serving name.

      mortgage_approval_service
      
    4. Click Create.

  2. When the model is deployed successfully, return to the model inventory; From the navigation menu Navigation menu, choose Catalogs > Model inventory.

  3. For the Mortgage Approval Model Entry, click View details.

  4. Click the Asset tab. Under Model tracking, you can see that the model is now in the Deploy stage.

Checkpoint Check your progress

The following image shows the model entry with the model in the Deploy phase. Your model is now ready for you to evaluate in Watson OpenScale

Model entry in Deploy phase

As a data scientist at Golden Bank, you created a mortgage approval model by running a Jupyter Notebook that built the model and automatically captured metadata to track the model in an AI Factsheet. You then promoted the model to a deployment space, and deployed the model.

Next steps

You are now ready to validate and monitor your deployed machine learning model to ensure it is working accurately and fairly. For this task, you will use Watson OpenScale. See the Test and validate the model tutorial.

Learn more

Parent topic: Data fabric tutorials