Home > OS >  TypeError: __init__() missing 1 required positional argument: 'data'
TypeError: __init__() missing 1 required positional argument: 'data'

Time:06-05

In Python, I have read in a lightGBM pmml file named flaml_lgbm.pmml, like so:

from pypmml import Model

model = Model.fromFile('flaml_lgbm.pmml')

Then I have tried to generate the SHAP graph with these lines of code:

shap_values = shap.KernelExplainer(model).shap_values(X)
shap.summary_plot(shap_values, X, plot_type="bar")

# positive and negative relationships of the predictors with the target variable
shap.summary_plot(shap_values, X)  

But I get this error:

shap_values = shap.KernelExplainer(model).shap_values(X)

TypeError: __init__() missing 1 required positional argument: 'data'

What is wrong with the code, and how can I fix it?

CodePudding user response:

You simply need to include data also in shap.KernelExplainer(), try this:

shap_values = shap.KernelExplainer(model, X).shap_values(X)
  • Related