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.
Questo esercizio fa parte del corso
Explainable AI in Python
Istruzioni dell'esercizio
- Create a SHAP tree explainer named
explainer. - Compute
shap_values. - Compute the mean absolute SHAP values
mean_abs_shap.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
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()