-2

i have text data and pip line model . i want to using shap library to Visualize the impact on all the output classes

i got this error :

TypeError: The passed model is not callable and cannot be analyzed directly with the given masker! Model: Pipeline(steps=[('vect1', CountVectorizer()),
                ('tfidf1', TfidfTransformer()), ('clf1', MultinomialNB())])

how can i handle it

desertnaut
  • 57,590
  • 26
  • 140
  • 166
MelinA
  • 1
  • 8

1 Answers1

0

try this :

vectorized_data = pipe_model1.named_steps['vect1'].transform(background_data)
transformed_background_data =pipe_model1.named_steps['tfidf1'].transform(vectorized_data)
explainer = shap.KernelExplainer(pipe_model1.named_steps['clf1'].predict_proba, transformed_background_data)
shap_values = explainer.shap_values(transformed_background_data)

the background_data is your data to use

your using the pipeline model and you should add your pip line model sequensly

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Ilya
  • 1
  • 5
  • 18