Model Explanations with Tabular Data

In this demo we will:

  • Launch an income classification model which has tabular training features

  • Send a request to get a prediction

  • Create an explainer for the model

  • Send the same request and then get an explanation for it

This demo uses a model trained to predict high or low income based on demographic features from a 1996 US census.

The explanation will offer insight into why an input was classified as high or low. It uses the anchors technique to track features from training data that correlate to category outcomes.

Create Model

  1. Click on Create new deployment button.

  2. Enter the deployment details as follows:

  • Name: income-classifier

  • Namespace: seldon

  • Type: Seldon Deployment

  • Protocol: Seldon

Expand to see deployment

Deployment details

  1. Configure the default predictor as follows:

  • Runtime: Scikit Learn

  • Model URI: gs://seldon-models/sklearn/income/model-0.23.2

  • Model Project: default

  • Storage Secret: (leave blank/none)

Expand to see default predictor

Default predictor spec

  1. Skip Next for the remaining steps, then click Launch.

  2. If your deployment is launched successfully, it will have Available status, on the overview page.

Get Predictions

  1. Click on the income-classifier deployment created in the previous section to enter the deployment dashboard.

  2. Inside the deployment dashboard, on the left navigation drawer, click on the Predict button.

  3. On the Predict page, enter the following text:

{
  "data": {
    "names": [
      "Age",
      "Workclass",
      "Education",
      "Marital Status",
      "Occupation",
      "Relationship",
      "Race",
      "Sex",
      "Capital Gain",
      "Capital Loss",
      "Hours per week",
      "Country"
    ],
    "ndarray": [
      [
        53,
        4,
        0,
        2,
        8,
        4,
        2,
        0,
        0,
        0,
        60,
        9
      ]
    ]
  }
}
  1. Click the Predict button. A screenshot showing the Predict page with the textarea prepopulated

Add a Tabular Explainer

There are currently 2 explainers available for tabular data classification:

  • Anchor Explainer

  • Kernel SHAP Explainer

  1. From the income-classifier deployment dashboard, click Add inside the Model Explanation card. The "Create" button inside the Model Explanation card being clicked

  2. For step 1 of the Explainer Configuration Wizard, select Tabular then click Next. Text radio option selected

  3. For step 2, click the Anchor radio button, then click Next.

    For step 3, enter the following value for the Explainer URI:

    gs://seldon-models/sklearn/income/explainer-py38-0.9.4
    

    then click Next

  4. For step 4, click Next. (Do not change any fields). Next button clicked

  5. For step 5, click Next. (Do not change any fields). You may wish to enter a comment here for a gitops enabled namespace. Next button clicked

  6. For step 6, click Launch. Next button clicked

After a short while, the explainer should become available.

Explainer status showing Available

Get Explanation for one Request

  1. Navigate to the Requests page using the left navigation drawer.

  2. Click on the View explanation button to generate explanations for the request.

    Anchor Explanation

Congratulations, you’ve created an explanation for the request! 🥳

The anchors reveal which features most contributed to the classification of ‘Low Income’. Here, for nearly 98% of the training data a Marital Status of ‘Separated’ correlates to Low Income. Having no Capital Gain also correlates but is a less strong indicator.

At the bottom we are shown other examples of Low Income data points. This helps to reveal the patterns that the model is relying on to make predictions.

Next Steps

Why not try our other demos? Ready to dive in? Read our operations guide to learn more about how to use Enterprise Platform.