[Python] SHAP value in TreeExplainer: Additivity check failed in TreeExplainer

Discussão em 'Python' iniciado por Stack, Abril 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to obtain the SHAP values of a Random Forest model for binary classification, trained in Python. I am using the following code:

    final_model = RandomForestClassifier(random_state=42, **best_params)

    final_model.fit(X_full, y_full)

    explainer = shap.TreeExplainer(final_model,feature_perturbation='interventional')

    shap_values = explainer.shap_values(X_full)

    However, I get the following error:

    ExplainerError: Additivity check failed in TreeExplainer! Please ensure the data matrix you passed to the explainer is the same shape that the model was trained on. If your data shape is correct then please report this on GitHub. Consider retrying with the feature_perturbation='interventional' option. This check failed because for one of the samples the sum of the SHAP values was -1493582.939642, while the model output was 0.229084. If this difference is acceptable you can set check_additivity=False to disable this check.

    I have also tried using shap_values = explainer(np.array(X_full)), as suggested in


    However, I get the same error.

    I would appreciate some help!

    Thanks!

    Continue reading...

Compartilhe esta Página