Aan de slagGa gratis aan de slag

Evaluating SHAP explanation consistency

Evaluate the consistency of feature importance explanations using SHAP values across two different subsets of the insurance dataset.

The subsets X1, X2, y1, and y2 have been pre-loaded for you along with model1 trained on the first subset and model2 trained on the second subset.

Deze oefening maakt deel uit van de cursus

Explainable AI in Python

Cursus bekijken

Oefeninstructies

  • Calculate shap_values1 and feature_importance1 for model1.
  • Calculate shap_values2 and feature_importance2 for model2.
  • Calculate consistency between feature importances.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Calculate SHAP values and feature importance for model1
explainer1 = shap.TreeExplainer(model1)
shap_values1 = ____
feature_importance1 = ____

# Calculate SHAP values and feature importance for model2
explainer2 = shap.TreeExplainer(model2)
shap_values2 = ___
feature_importance2 =____

# Consistency calculation
consistency = ____
print("Consistency between SHAP values:", consistency)
Code bewerken en uitvoeren