我使用 pythonshap包来更好地理解我的机器学习模型。(来自文档:“SHAP(SHapley Additive exPlanations)是一种博弈论方法,用于解释任何机器学习模型的输出。”下面是我收到的错误的一个可重现的小示例:
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import shap
>>> shap.__version__
'0.37.0'
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.linear_model import LogisticRegression
>>>
>>> iris = shap.datasets.iris()
>>> X_train, X_test, y_train, y_test = train_test_split(*iris, random_state=1)
>>> model = LogisticRegression(penalty='none', max_iter = 1000, random_state=1)
>>> model.fit(X_train, y_train)
>>>
>>> explainer = shap.Explainer(model, data=X_train, masker=shap.maskers.Impute(),
... feature_names=X_train.columns, …Run Code Online (Sandbox Code Playgroud)