Finding key heart disease predictors with SHAP
Your task is to use SHAP to understand how different features in a pre-trained RandomForestClassifier model
influence predictions for heart disease.
X
containing the features and y
containing the labels, and the random forest classifier model
have been pre-loaded for you.
This exercise is part of the course
Explainable AI in Python
Exercise instructions
- Create a SHAP tree explainer named
explainer
. - Compute
shap_values
. - Compute the mean absolute SHAP values
mean_abs_shap
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
import shap
# Create a SHAP Tree Explainer
explainer = ____
# Calculate SHAP values
shap_values = ____
# Calculate mean absolute SHAP values
mean_abs_shap = ____
plt.bar(X.columns, mean_abs_shap)
plt.title('Mean Absolute SHAP Values for RandomForest')
plt.xticks(rotation=45)
plt.show()