我正在运行 3 个不同的模型(随机森林、梯度提升、Ada Boost)和基于这 3 个模型的模型集合。
我设法将 SHAP 用于 GB 和 RF,但不适用于 ADA,但出现以下错误:
Exception Traceback (most recent call last)
in engine
----> 1 explainer = shap.TreeExplainer(model,data = explain_data.head(1000), model_output= 'probability')
/home/cdsw/.local/lib/python3.6/site-packages/shap/explainers/tree.py in __init__(self, model, data, model_output, feature_perturbation, **deprecated_options)
110 self.feature_perturbation = feature_perturbation
111 self.expected_value = None
--> 112 self.model = TreeEnsemble(model, self.data, self.data_missing)
113
114 if feature_perturbation not in feature_perturbation_codes:
/home/cdsw/.local/lib/python3.6/site-packages/shap/explainers/tree.py in __init__(self, model, data, data_missing)
752 self.tree_output = "probability"
753 else:
--> 754 raise Exception("Model type not yet supported by TreeExplainer: " + str(type(model)))
755
756 # build a dense numpy version of all the tree objects
Exception: Model type not yet supported by TreeExplainer: <class 'sklearn.ensemble._weight_boosting.AdaBoostClassifier'>
我在 Git 上找到了这个链接
TreeExplainer
从我们试图解释的任何模型类型创建一个 TreeEnsemble 对象,然后与该下游一起工作。所以你需要做的就是在
TreeEnsemble
类似于梯度提升的构造函数
但我真的不知道如何实现它,因为我对此很陌生。