How to interpretate shapvalue of a single observation

291 Views Asked by At

I trained an XGBoost model to predict excavation damages. There are 123 features and the target classes are 1 (damage) or 0 (no damage). Now for each prediction, I am required to give a list of most important features for this certain instance. So I tried Shap to get shapevalues for a single observatrion by explainer = shap.Explainer(model, input_array) shap_values = explainer(input_array) But I have two questions about interpretating the result:

  1. I think the shap value should be a list of values, in which positive value means the contribution to positive result and negative value means the contribution to negative result. But after I tried about 5 instances, I found only positive values. Below is an example of the shape values for an instance. Most of the features have the shap value of 0, which means that these features are usefless for this prediction I think. But I don't understand why there is no negative value.
array([[0.00000000e+00, 9.92100000e+01, 1.00000000e+00, 4.00000000e+00,
        2.50000000e+01, 4.00000000e+00, 2.00000000e+01, 6.00000000e+00,
        1.13380000e+02, 1.00000000e+00, 0.00000000e+00, 1.00000000e+00,
        1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00,
        0.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00,
        1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        1.63470000e+04, 2.42600000e+03, 6.90000000e+01, 2.98800000e+03,
        4.22000000e+03, 2.30000000e+01, 4.60759023e+02, 1.09184603e-01,
        3.67600000e+01, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 5.77357590e+01,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
        0.00000000e+00, 4.16226424e+03, 0.00000000e+00]])
  1. I found from somewhere that, the predicted probability = the aggregation of shap values + expected value. But when I tried to aggregate shap values of instance A and instance B. Instance A has the predicted probability of 0.38, and the aggregated shap value of 111147.29. Instance B has the predicted probability of 0.74, and the aggregated values value of 31077.21. Why A has a higher aggregated shap value than B?
1

There are 1 best solutions below

6
On BEST ANSWER

Regarding your first question (only positive values):

You're correct that SHAP values represent a contribution to the prediction. To elaborate: they contribute to a base value, calculated as Base value + contrib. 1 + contrib. 2 + ... = Final value. If your base value is low, you might mostly see positive SHAP values. Another possibility is that your model is biased, which could also result in mainly positive values.

Regarding your second question (relationship between SHAP values and predicted probabilities):

You've understood the relationship between SHAP values and predicted probabilities correctly: the predicted output is the sum of the SHAP values and the expected value (the average prediction across the training dataset). However:

  • You should aggregate the SHAP values per feature, not across all features.
  • Be cautious when comparing aggregated SHAP values between different instances like A and B. These explanations are instance-specific, and varying numbers of features may contribute to the predictions for different instances.