Icon

Arlington_​UT_​xAI_​Exercise

<p>Solution for xAI exercise @ UT Arlington</p>

Solution for xAI exercise @ UT Arlington

Read dataset
This is done for you already! Here we read in a local dataset from kaggle using a CSV reader.



Building a EXplainable Predictive Model for Heart Disease

Dataset used: https://www.kaggle.com/datasets/fedesoriano/heart-failure-prediction/data

Follow the steps below, to create a model using a random forest! At the end, you can try to do the EXTRA part in the red box where we apply an additional component called LIME for more insight into how our model behaves.

Data Transformation

  1. Add a 'Missing Value' Node to clean our input. This is standard and for our case just set in the configuration to remove the row if such a row exists.

    1. Configuration can be done by hovering over the node and clicking on the 'gear' icon

  2. Use the new 'Expression' node to prepare our results category to be used as the target column, you need to add a formula such that IF HeartDisease is 1, then output 'True'; Otherwise output 'False'. Replace the value of the existing field.

    1. If you need a hint on how to do this, open the metanode to get the formula!

  3. Check out the distributions of the dataset using the 'Statistics' node; This can give insight on if we have a minority of a particular category. You can just place this node on a separate branch and open its view.

  4. We are done with our data prep! Now you need to partition the data (connect expression output to 'Partitioning' node) into a 80:20 split where 80% is the training set, and 20% is the testing set. In the config, check mark the 'Stratified Sampling' on HeartDisease as typically datasets often are not balanced

Training the Model

  1. Here we provide pre-configured Workflow Capture nodes that will be used for our xAI components

  2. Drag and Drop a Random Forest Learner and connect the testing data set port from 'Partitioning' node to the node input

  3. Click on the node, and click the configuration (gear icon) --> HeartDisease should be selected in the 'Target Column' option. Keep all features included

  4. Add the 'Random Forest Predictor' node and connect it with the 'Random Forest Learner' via the model port (light grey box)

  5. Connect the testing set output port from the 'Partitioning' node to the input table port on the 'Capture Workflow Start'. Take the output from this node and connect it to the input table port on the 'Random Forest Predictor'.

  6. And your model is built! Connect the output of the Predictor to the 'Capture Workflow End'. You can check out how accurate the model is by adding a 'Scorer (JavaScript)' after the 'Capture Workflow End'

  7. In the Scorer, set in the config, Actual Column = HeartDisease and Predicted Column = Prediction (HeartDisease)

EXTRA: Apply LIME to the RF model

  1. Take your existing 'Random Forest Learner' and 'Random Forest Predictor' from above and copy/paste them below. Connect the training set from the Partitioning node, as you did before, to the learner. We do not need the Workflow Captures for this case.

  2. Add in a 'Row Sampling' node and connect it to the test set from the Partitioning node. We'll use this to sample 10 rows from the testing set that we want to evaluate with LIME

  3. We provided a 'LIME Loop Start' node:

    1. The top input port takes as input the rows to be explained (the 10 from 'Row Sampling')

    2. Connect the whole test set from 'Partitioning' node to the bottom port

    3. Connect the top output port to the table input port for the 'Random Forest Predictor'

    4. Connect the bottom output port to the bottom port in the provided 'Compute LIME' component

  4. Take the output of the 'Random Forest Predictor' and connect it to the top input of the 'Compute LIME' component

  5. Check the box in the Predictor configuration to append individual class probabilities

  6. Configure the LIME component to make sure we target P(HeartDisease)=True. You may need to execute it one with its default configuration, then reconfigure it.

  7. The component then needs to be wrapped in a loop, so add in the 'Loop End' node and connect the output of the component with the loop input

  8. Add a 'Bar Chart' to visualize the results and connect the output from the 'Loop End'

    1. Reorient the bar chart to be horizontal inside the node configuration. Remove fileds generated by like iteration, RMSE, and intercept.

Applying xAI to the model (pt. 1)

  1. We provided the 2 components necessary to add in explainable AI. These are the 'Local Explanation View' and 'Global Feature Importance'

  2. Starting with the 'Local Explanation View', we need to prepare the input for it.

    1. The top port is a workflow object type (black square). Note that in the previous section, the 'Random Forest Predictor' node should be wrapped between the Workflow Capture nodes.

    2. Take the workflow object output port from 'Capture Workflow End' and connect it to the top workflow object port on the 'Local Explanation View' component. Also take the table output port from 'Capture Workflow End' and connect it to the provided metanode 'Single Instance (LEV)'.

      1. 'Single Instance (LEV)' handles singling out a instance to be explained (for this case we find patient wrongly predicted to not have heart disease while they do have it)

    3. The middle input port of the 'Local Explanation View' will just take in all our training data we used, so connect the test set output port. Take this from the 'Capture Workflow Start' output in the previous section

    4. The last/bottom input port on the 'Local Explanation View' needs to take in the single instance, so just connect the output from the provided metanode to it

  3. Execute the component; right-click and click 'Open View'

Applying xAI to the model (pt. 2)

  1. Now we will connect the 'Global Feature Importance' component

  2. Take the workflow object output from the 'Capture Workflow End' and connect it with the top port on 'Global Feature Importance'

  3. Again, we need the test set for the bottom port, so pull from the 'Capture Workflow Start' output port and connect it with the bottom input port of the component

  4. Click on the configuration and uncheck the Surrogate Generalized Linear Model in importance methods

  5. Execute and Click on "Open View"


Read in heart-disease dataset
CSV Reader
Input: 0 : Model as a Workflow Object 1 : Data from Model Test Partition Output: 0 : Global Feature Importance
Global Feature Importance
top input : test rows to be explainedbottom input : test set distribution
LIME Loop Start
Capture Workflow End
Need a hint forExpression Node?
Hint
training a local GLM for each input instance to generate a Local Inter. Model-agn. Explanation
Compute LIME
Input: 0 : Model as a Workflow Object 1 : Data from Model Test Partition 2 : Single Instance to Explain Output: 0 : Counterfactuals Instances 1 : Local Feature Importance
Local Explanation View
Single Instance (LEV)
Capture Workflow Start

Nodes

Extensions

Links