我正在使用 shap 库来比较几个模型,其中一个是正则化线性回归,但是当我尝试创建解释器时:
shap.KernelExplainer(linear_reg,X1)
我收到以下错误:
\Anaconda3\lib\site-packages\shap\common.py in match_model_to_data(model, data)
87 out_val = model.f(data.convert_to_df())
88 else:
---> 89 out_val = model.f(data.data)
90 except:
91 print("Provided model function fails when applied to the provided data set.")
TypeError: 'Lasso' object is not callable
下面是重现此错误的代码:
from sklearn.datasets import make_regression¿
from sklearn.linear_model import LinearRegression
import shap
from sklearn import linear_model
X1,y1= make_regression(10,100)
linear_reg = linear_model.Lasso(alpha=0.1)
linear_reg.fit(X1, y1)
shap.initjs()
explainer = shap.KernelExplainer(linear_reg,X1)