Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw warning and update error message #3576

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions shap/explainers/_tree.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io
import json
import logging
import os
import time
import warnings
Expand Down Expand Up @@ -73,6 +74,8 @@ def _xgboost_cat_unsupported(model):
)


logger = logging.getLogger(__name__)

class TreeExplainer(Explainer):
"""Uses Tree SHAP algorithms to explain the output of ensemble tree models.

Expand Down Expand Up @@ -182,7 +185,7 @@ def __init__(
self.data = data
if self.data is None:
feature_perturbation = "tree_path_dependent"
#warnings.warn("Setting feature_perturbation = \"tree_path_dependent\" because no background data was given.")
logger.warning("Setting feature_perturbation = \"tree_path_dependent\" because no background data was given.")
elif feature_perturbation == "interventional" and self.data.shape[0] > 1_000:
wmsg = (
f"Passing {self.data.shape[0]} background samples may lead to slow runtimes. Consider "
Expand Down Expand Up @@ -351,8 +354,9 @@ def _validate_inputs(self, X, y, tree_limit, check_additivity):
"so TreeExplainer cannot run with the "
"feature_perturbation=\"tree_path_dependent\" option! "
"Try providing a larger background "
"dataset, no background dataset, or using "
"feature_perturbation=\"interventional\"."
"dataset, no background dataset, using "
"feature_perturbation=\"interventional\" or "
"reducing the number of trees might help."
)
raise ExplainerError(emsg)

Expand Down