我训练了以下 XGBClassifier:
model = XGBClassifier( #XGBClassifier
objective='binary:logistic',
base_score=0.5,
booster='gbtree',
colsample_bylevel=1,
colsample_bynode=1,
colsample_bytree=1,
enable_categorical=False,
gamma=2,
gpu_id=-1,
importance_type=None,
interaction_constraints='',
learning_rate=0.1,
max_delta_step=0,
max_depth=3,
min_child_weight=7,
monotone_constraints='(1,1,1,1,1)',
n_estimators=12,
n_jobs=1,
nthread=1,
num_parallel_tree=1,
predictor='auto',
random_state=0,
reg_alpha=0,
reg_lambda=1,
scale_pos_weight=1,
silent=True,
subsample=0.8,
tree_method='exact',
validate_parameters=1,
pred_contribs=True,
verbose=True)
model.fit(X, Y)
然后我尝试使用以下代码生成 SHAP 值:
explainer = shap.GradientExplainer(model,data = X)
shap_values = explainer.shap_values(X)
但我得到这个错误:
File "C:\Users\glevorato\Anaconda3\lib\site-packages\shap\explainers\tf_utils.py", line 68, in _get_model_inputs
assert False, str(type(model)) + " is not currently a supported model type!"
AssertionError: <class 'xgboost.sklearn.XGBClassifier'> is not currently a supported model type!
有人知道为什么吗?是因为不支持 XGBClassifier 吗?我需要使用 GradientExplainer:XGBClassifier 的替代品是什么?