AI governance tutorial: Test and validate the model

Take this tutorial to evaluate and monitor the model built and deployed in the Build and deploy a model tutorial with the AI governance use case. Your goal is to use Watson OpenScale to configure and evaluate monitors for a deployed model that predicts which applicants qualify for mortgages. You want to ensure that the model is accurate and treating all applicants fairly.

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 set up monitors for a machine learning model so that you can deploy them into productive use with confidence that they operate effectively and as intended. This task is accomplished through Cloud Pak for Data services, which together deliver trust in your data, trust in your models, and trust in your processes that are required to operate AI with certainty.

The following animated image provides a quick preview of what you’ll accomplish by the end of this tutorial. Right-click the image and open it in a new tab to view a larger image.

Screenshots of the tutorial

Preview the tutorial

In this tutorial, you will complete these tasks:

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 to learn the concepts and tasks in this documentation.


Try the tutorial

Expand each section to complete the task.



Tips for completing this tutorial
Here are some tips for successfully completing this tutorial.

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.



Set up the prerequisites

Complete the Build and deploy a model tutorial

Complete the Build and deploy a model tutorial to create, promote, and deploy the machine learning model that is used in this tutorial.




Task 1: Run the notebook to set up the monitors

Run the second notebook included in the sample project to:

  • Fetch the model and deployments.
  • Configure Watson OpenScale.
  • Create the service provider and subscription for your machine learning service.
  • Configure the quality monitor.
  • Configure the fairness monitor.
  • Configure explainability.

Follow these steps to run the notebook included in the sample project. This notebook sets up monitors for your model, which can also be configured through the user interface. However, it is quicker and less error prone to set them up with a notebook. 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. Open the AI governance project.

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

  4. Click the Overflow menu Overflow menu for the 2-monitor-wml-model-with-watson-openscale notebook, and choose Edit.

  5. Click Run > Run All Cells to run all of the cells in the notebook. Alternatively, click the Run icon Run to run the notebook cell by cell if you want to explore each cell and its output.

  6. The third cell requires your input.

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

    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.

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

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

    • Click Kernel > Restart & Clear Output to restart the kernel, and then run the notebook again.
    • Verify that you created the model use case, deployment space, and deployment name in the Build and deploy a model tutorial 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 set up monitors for your model, so you can now view the deployment in Watson OpenScale.

Notebook




Task 2: Evaluate the model

Follow these steps to download holdout data, and use that data to evaluate the model in Watson OpenScale:

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

  2. On the Assets tab, click Data > Data assets.

  3. Click the Overflow menu Overflow menu for the GoldenBank_HoldoutData.csv data asset, and choose Download. To validate that the model is working as required, you need a set of labeled data, which was held out from model training. This CSV file contains that holdout data.

  4. Launch Watson OpenScale.

    1. From the Cloud Pak for Data navigation menu Navigation menu, choose Services > Instances.

    2. On the Instances page, click the Overflow menu Overflow menu at the end of the row for your Watson OpenScale instance, and choose Open.

  5. On the Insights dashboard, click the Mortgage Approval Model Deployment tile.

  6. From the Actions menu, select Evaluate now.

  7. From the list of import options, select from CSV file.

  8. Drag the Golden Bank_HoldoutData.csv data file you downloaded from the project into the side panel.

  9. Click Upload and evaluate.

Checkpoint icon Check your progress

The following image shows the result of the evaluation for the deployed model in Watson OpenScale. Now that you evaluated the model, you are ready to observe the model quality.

Evaluation




Task 3: Observe the model monitors for quality

The Watson OpenScale quality monitor generates a set of metrics to evaluate the quality of your model. You can use these quality metrics to determine how well your model predicts outcomes. When the evaluation that uses the holdout data completes, follow these steps to observe the model quality or accuracy:

  1. In the left navigation panel, click the Insights dashboard icon InsightInsight dashboard dashboard.

  2. Locate the Mortgage Approval Model Deployment tile. Notice that the deployment has 0 issues, and that both Quality and Fairness tests passed, meaning that the model met the thresholds that are required of it.

  3. Click the Mortgage Approval Model Deployment tile to see more detail.

  4. In the Quality section, click the Configure icon Configure. Here you can see that the quality threshold that is configured for this monitor is 70% and that the measurement of quality being used is area under the ROC curve.

  5. Click Go to model summary to return to the model details screen.

  6. In the Quality section, click the Details icon Details to see the model quality detailed results. Here you see a number of quality metric calculations and a confusion matrix showing correct model decisions along with false positives and false negatives. The calculated area under the ROC curve is 0.9 or higher, which exceeds the 0.7 threshold, so the model is meeting its quality requirement.

  7. Click Mortgage Approval Model Deployment in the navigation trail to return to the model details screen.

Checkpoint icon Check your progress

The following image shows the quality details in Watson OpenScale. Now that you observed the model quality, you can observe the model fairness.

Quality




Task 4: Observe the model monitors for fairness

The Watson OpenScale fairness monitor generates a set of metrics to evaluate the fairness of your model. You can use the fairness metrics to determine if your model produces biased outcomes. Follow these steps to observe the model fairness:

  1. In the Fairness section, click the Configure icon Configure. Here you see that the model is being reviewed to ensure that applicants are being treated fairly regardless of their gender. Women are identified as the monitored group for whom fairness is being measured and the threshold for fairness is to be at least 80%. The fairness monitor uses the disparate impact method to determine fairness. Disparate impact compares the percentage of favorable outcomes for a monitored group to the percentage of favorable outcomes for a reference group.

  2. Click Go to model summary to return to the model details screen.

  3. In the Fairness section, click the Details icon Details to see the model fairness detailed results. Here you see the percentage of male and female applicants who are being automatically approved, along with a fairness score of over 100%, so the model performance far exceeds the 80% fairness threshold required.

  4. Note the identified data sets. To ensure that the fairness metrics are most accurate, Watson OpenScale uses perturbation to determine the results where only the protected attributes and related model inputs are changed while other features remain the same. The perturbation changes the values of the feature from the reference group to the monitored group, or vice-versa. These additional guardrails are used to calculate fairness when the "balanced" data set is used, but you can also view the fairness results using only payload or model training data. Since the model is behaving fairly, you don't need to go into additional detail for this metric.

    Fairness data sets

  5. Click the Mortgage Approval Model Deployment navigation trail to return to the model details screen.

Checkpoint icon Check your progress

The following image shows the fairness details in Watson OpenScale. Now that you observed the model fairness, you can observe the model explainability.

Fairness




Task 5: Observe the model monitors for explainability

It is also important to understand how the model came to its decision. This understanding is required both to explain decisions to people involved in the loan approval and to ensure model owners that the decisions are valid. To understand these decisions, follow these steps to observe the model explainability:

  1. In the left navigation panel, click the Explain a transaction icon Explain a transaction.

  2. Select Mortgage Approval Model Deployment to see a list of transactions.

  3. For any transaction, click Explain under the Actions column. Here you see the detailed explanation of this decision. You will see the most important inputs to the model along with how important each was to the end result. Blue bars represent inputs that tended to support the model's decision while red bars show inputs that might have led to another decision. For example, an applicant might have enough income to otherwise be approved but their poor credit history and high debt together lead the model to reject the application. Review this explanation to become satisfied about the basis for the model decision.

  4. (Optional) If you want to delve further into how the model made its decision, click the Inspect tab. Use the Inspect feature to analyze the decision to find areas of sensitivity where a small changes to a few inputs would result in a different decision, and you can test the sensitivity yourself by overriding some of the actual inputs with alternatives to see whether these would impact the result.

Checkpoint icon Check your progress

The following image shows the explainability of a transaction in Watson OpenScale. You have determined that the model is accurate and treating all applicants fairly. Now, you can advance the model to the next phase in its lifecycle.

Explainability




Task 6: Promote the model to pre-production and approve the model

Follow these steps to change the status of the model use case in the model inventory and approve the model:

Task 6a: Request a model review

Before approving the model, follow these steps to request a final review:

  1. Return to Cloud Pak for Data, and from the Navigation Menu Navigation menu, choose AI governance > AI use cases.

  2. Click the Mortgage Approval Model Use Case.

  3. Click the Lifecycle tab. Under the approach, you can see that the model is now in the Validation phase.

  4. Return to the Overview tab, and click the Open in Governance Console link to open the same use case in IBM OpenPages Model Risk Governance.

  5. Under Associations > Models, click the Mortgage Approval Prediction Model name to view the model.

  6. Create a model review.

    1. Click the Admin tab.

    2. Scroll down to the Risk and Validation Activity section.

    3. Click the Model Reviews tab.

    4. Click New to create a new model review.

    5. For the Review type, select Pre Implementation Review.

    6. For the Scope, type:

      Pre-implementation review for mortgage approval model
      
    7. Click Save.

Task 6b: Validate the model

Next, the model validator walks through the workflow for model validation. The validator follows this workflow to complete several stages of model validation.

  1. Commence the fieldwork of testing and verifying the model.
  2. Mark the fieldwork as complete.
  3. Complete the validation.

Follow these steps to validate the model:

  1. Commence fieldwork. The fieldwork is the validation of the model that the validator performs.

    1. Click Action > Confirm Fieldwork Commenced.

    2. Click Continue.

    3. For the Conclusion, select Passed Review.

    4. For the Comments, type:

      Review complete and ready for final approval
      
    5. Click Save.

  2. Complete the fieldwork. After the validator completes the fieldwork, they follow these steps to mark the fieldwork as complete:

    1. Click Action > Complete Fieldwork.

    2. Click Continue.

  3. Complete the validation. After the fieldwork is marked complete, the validator compiles a report of their findings and attaches it to the model review, and then follows these steps to complete the validation:

    1. Optional: In the Associated files section, note the option to upload a report.

    2. Click Action > Complete Validation.

    3. Click Continue.

  4. The model reviewer follows these steps to confirm that the model validation is complete:

    1. Switch to the Mortgage Approval Prediction Model.

    2. Click the Admin tab.

    3. Click the Edit icon Edit next to the Candidate Status field.

    4. Select Confirmed, and click Save.

    5. Click the Edit icon Edit next to the Model Status field.

    6. Select Validation Complete, and click Save.

Task 6c: Submit the model for approval

Follow these steps to approve the model. At this stage, the model approver reviews the model, including the risk assessment and model review. If all of the results are satisfactory, they follow these steps to approve the model for deployment in a production environment:

  1. Click the Edit icon Edit next to the Model Status field.

  2. Select Approved for Deployment, and click Save.

  3. On the Task tab*, click the link in the Third Party Link field to open the use case in the model inventory.

  4. On the Overview tab, click the Edit icon Edit next to the Status field.

  5. Select AI asset approved, and click Apply.

Checkpoint icon Check your progress

The following image shows the approved model use case.

Approved model use case




Task 7: Share the model

You can generate a report from a factsheet or model use case in PDF, HTML, and DOCX format so you can share or print the details about a model being tracked in a model inventory.

  1. From the Overview tab in the model use case, click Export report.

  2. For the Format options, choose a format.

  3. For the Report template, select a template:

    • Model use case basic report: contains the set of facts visible on the Overview and Assets tabs.

    • Model use case full report: contains all data from the Basic report and details about the models and deployments in the model use case.

  4. Click Export.

  5. View the PDF report.

Checkpoint icon Check your progress

The following image shows the full report for the Mortgage Approval Model Use Case. You can now share this report with your colleagues.

Model use case report



As a data scientist at Golden Bank, you created a mortgage approval model that avoids unanticipated risk and treats all applicants fairly. You ran a Jupyter notebook to set up monitors for your machine learning model which you deployed into productive use with confidence that the model operates effectively and as intended.


Cleanup (Optional)

If you would like to retake the tutorials in the AI governance use case, delete the following artifacts.

Artifact How to delete
Mortgage Approval Model Deployment in the Golden Bank Preproduction Space Delete a deployment
Golden Bank Preproduction Space Delete a deployment space
Mortgage Approval Model Use Case Delete a model use case
Mortgage Approval Catalog Delete a catalog
AI governance sample project Delete a project

Next steps

Learn more

Parent topic: Use case tutorials