We have moved to a new Address!
Throughout this tutorial we will be using shap plots based on Heart failure clinical records dataset which is binary classification dataset.
A variable importance plot lists the most significant features in decreasing order over complete dataset. The features at top of the chart contribute more to the model than the bottom ones and thus have high predictive power with a relative feature strengths depicted by horizontal bars.
shap.summary_plot(shap_values, val_X)
From the plot above we can figure out that follow up time is the most important factor deciding the end condition of the patient.
The SHAP summary plot can further show the positive and negative relationships of the predictors with the target variable for each class.
shap.summary_plot(shap_values[0], val_X)
This plot is made of all the data points in the train data. It demonstrates the following information:
Feature importance: Variables are ranked in descending order.
Impact: The horizontal location shows whether the effect of that value is in favor of current class or not.
Original value: Color shows whether that variable value is high or low for that observation.
Correlation: A high value of the time feature has negative impact on target prediction. Similarly, we can say a low value of serum creatinine is negatively correlated with the target.
This plot helps us interpret individual observations, marginal contributions of different attributes on that observation. This is what we call local interpretability as opposed to what we saw above which is global interpretability (interpreting impact of the variables on the model overall)
shap.force_plot(explainer.expected_value[0], shap_values[0][0],feature_names = feature_names)
Here we have plotted the figure for first observation in the dataset. It demonstrates following information:
The base value: This is the mean of all observation predictions that were considered while training the model. Here 0.74 is the base value
Red/blue: Features that push the prediction higher (to the right) are shown in red, and those pushing the prediction lower are in blue.
The size of the bar depicts the relative contribution of features to the observation prediction.
This is same as force plot but instead of single observation, it allows to see the characteristics over the multiple data points at the same time.
shap.force_plot(explainer.expected_value[0], shap_values[0],feature_names = feature_names)
The graph is nothing but a cluster of multiple single observation force plots aligned vertically side by side.
This is another instance of global interpretability. Given a target feature, shap can plot the relationship graph b/w feature and its shapley values over global dataset.
shap.dependence_plot(0, shap_values[0], val_X)
This is a simple plot of shap values of age feature for all the data points. Though it gives a lot of insights. As can be seen in the figure most of the points that fall in the age range of 40 - 70 have a positive effect on target prediction. And it is only after 70 that the direction of impact changes. Further it shows the correlation between age and cretainine_phosphokinase by the medium of heat scale.