0 / 0
AI governance tutorial: Build and deploy a model

AI governance 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 AI governance use case. 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.

Quick start: If you did not already create the sample project for this tutorial, access the AI governance sample project in the Resource hub.

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.

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. Click the image to view a larger image.

Animated image

Preview the tutorial

In this tutorial, you will complete these tasks:

Watch Video Watch this video to preview the steps in this tutorial.

This video provides a visual method to learn the concepts and tasks in this documentation.




  • Use the video picture-in-picture

    Tip: Start the video, then as you scroll through the tutorial, the video moves to picture-in-picture mode. Close the video table of contents for the best experience with picture-in-picture. You can use picture-in-picture mode so you can follow the video as you complete the tasks in this tutorial. Click the timestamps for each task to follow along.

    The following animated image shows how to use the video picture-in-picture and table of contents features:

    How to use picture-in-picture and chapters

    Get help in the community

    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.

    Set up your browser windows

    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

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

    Back to the top

  • Sign up for Cloud Pak for Data as a Service

    You must sign up for Cloud Pak for Data as a Service and provision the necessary services for the Data integration use case.

    • If you have an existing Cloud Pak for Data as a Service account, then you can get started with this tutorial. If you have a Lite plan account, only one user per account can run this tutorial.
    • If you don't have a Cloud Pak for Data as a Service account yet, then sign up.

    Verify the necessary provisioned services

    preview tutorial video To preview this task, watch the video beginning at 01:06.

    Important: Model inventory is available in the Dallas region only. If necessary, switch to the Dallas region before continuing.

    Follow these steps to verify or provision the necessary services:

    1. In Cloud Pak for Data, verify that you are in the Dallas region. If not, click the region drop down, and then select Dallas.
      Change region

    2. From the Cloud Pak for Data navigation menu Navigation menu, choose Services > Service instances.

    3. Use the Product drop-down list to determine whether there is an existing Watson Studio service instance.

    4. If you need to create a Watson Studio service instance, click Add service.

    5. Select Watson Studio.

      1. For the region, select Dallas.

      2. Select the Lite plan.

      3. Click Create.

    6. Repeat these steps to verify or provision the following additional services:

      • Watson Machine Learning
      • IBM Knowledge Catalog
      • Cloud Object Storage

    Checkpoint icon Check your progress

    The following image shows the provisioned service instances:

    Provisioned services

    Create the sample project

    preview tutorial video To preview this task, watch the video beginning at 01:45.

    1. Access the AI governance sample project in the Resource hub.

    2. Click Create project.

    3. If prompted to associate the project to a Cloud Object Storage instance, select a Cloud Object Storage instance from the list.

    4. Click Create.

    5. Wait for the project import to complete, and then click View new project to verify that the project and assets were created successfully.

    6. Click the Assets tab to view the assets in the sample project.

    Note: You might see a guided tour showing the tutorials that are included with this use case. The links in the guided tour will open these tutorial instructions.

    Checkpoint icon Check your progress

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

    Sample project


    Back to the top


  • preview tutorial video To preview this task, watch the video beginning at 02:35.

    You track models by adding model use cases to a catalog. With the IBM Knowledge Catalog Lite plan, you can create two catalogs. Follow these steps to see whether you already have a catalog and, if not, to create a catalog to store the model use case:

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

    2. If you see a catalog on the Catalogs page, then you can skip to Task 2: Create the model use case in the model inventory. Otherwise, follow these steps to create a new catalog:

      1. Click New Catalog.

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

        Mortgage Approval Catalog
        
      3. If prompted to associate the catalog to a Cloud Object Storage instance, select a Cloud Object Storage from the list.

      4. Select Enforce data protection rules, confirm the selection, and accept the defaults for the other fields.

      5. Click Create.

    Checkpoint icon Check your progress

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

    Mortgage Approval Catalog


    Back to the top


  • preview tutorial video To preview this task, watch the video beginning at 3:08.

    For this type of project, it is best to create the model use case when a project commences. A model use case 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 use case and track the model as it progresses through its lifecycle. Follow these steps to create the model use case:

    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 use case.

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

      Mortgage Approval Model Use Case
      
    4. For the Description, copy and paste the following text:

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

    6. Click Save.

    Checkpoint icon Check your progress

    The following image shows your model use case. The model use case 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 Use Case


    Back to the top


  • preview tutorial video To preview this task, watch the video beginning at 03:50.

    Now you are ready to run the first notebook included in the sample project. The notebook includes the code to:

    • Set up AI Factsheets used to track the lifecycle of the model.
    • Load the training data, which is stored in the Db2 Warehouse connection in the sample project.
    • Specify the target, categorical, and numerical columns along with the thresholds used to build the model.
    • Build data pipelines.
    • Build machine learning models.
    • View the model results.
    • Save the model.

    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 > View all projects.

    2. Click the AI governance project name.

    3. Click the Assets tab, and then navigate to Notebooks.
      Left navigation

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

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

    6. When you import a project from the Resource hub, the first cell of the notebook contains the project access token. If this notebook does not contain a first cell with a project access token, you need to generate the token. From the More menu, select Insert project token. This action inserts a new cell as the first cell in the notebook containing the project token.

    7. Under the Provide your IBM Cloud API key section, you need to pass your credentials to the Watson Machine Learning API using an API key. If you don't already have a saved API key, then follow these steps to create an API key.
      preview tutorial video To preview this task, watch the video beginning at 04:44.

      1. Access the IBM Cloud console API keys page.

      2. Click Create an IBM Cloud API key. If you have any existing API keys, the button may be labelled Create.

      3. Type a name and description.

      4. Click Create.

      5. Copy the API key.

      6. Download the API key for future use.

      7. Return to the notebook, and paste your API key in the ibmcloud_api_key field.

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

    9. 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]".

    10. 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 use case by copying and pasting the specified artifact name exactly with no leading or trailing spaces.

    Checkpoint icon 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


    Back to the top


  • preview tutorial video To preview this task, watch the video beginning at 06:16.

    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 use case in the model inventory:

    1. Click the AI governance project name in the navigation trail.
      Navigation trail

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

    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. From the list of model use cases, select Mortgage Approval Model Use Case, and click Next.

      2. Select Default approach, and click Next.

      3. Select Experimental, and click Track model.

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

    7. On the model use case 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 icon Check your progress

    The following image shows the model use case 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 use case in Develop phase


    Back to the top


  • 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

    preview tutorial video To preview this task, watch the video beginning at 07:28.

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

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

    2. Click Open in project to open the model in the AI governance project.

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

    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. Select a storage service from the list.

      3. Select your provisioned machine learning service from the list.

      4. Click Create.

      5. 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 icon 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

    preview tutorial video To preview this task, watch the video beginning at 08:33.

    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 already exists, then add a number (or any unique character) to the end of the serving name.

        mortgage_approval_service
        
      4. Click Create.

    2. The model deployment may take several minutes to complete. 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 Use Case, click View details.

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

    Checkpoint icon Check your progress

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

    Model use case in Deploy phase


    Back to the top

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

Watch Video Watch how to use IBM OpenPages to manage the model through its lifecycle.

This video provides a visual method to learn the concepts and tasks in this documentation.

Parent topic: Use case tutorials

Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more