-1

I am trying to compute shape explainer so i can visualize my model. However I keep getting the following error:

Exception: The passed model is not callable and cannot be analyzed directly with 
the given masker! Model: SVC(C=300, probability=True)

my code:

model =  create_model(SVC, C=300, probability=True) #user defined function works right
model.fit(X_train, y_train)

explainer = shap.Explainer(model)
shap_values = explainer.shap_values(X_test)
 
shap.initjs()
shap.force_plot(explainer.expected_value,  X_train)

when I tried KernelExplainer along with X_train I got:

TypeError: 'SVC' object is not callable

Edit:

Here is the create_model function which takes the training variables and other model keywords as parameters:

def create_model(X_train, y_train, model, **kwargs):
    created_model = model(**kwargs)
    created_model.fit(X_train,y_train)
    
    return created_model

Also here is the progress bar after trying recommended answer: progress bar screenshot

DataDev98
  • 3
  • 1
  • 3

1 Answers1

0

First off, you need to pass your model's predict method, not the model on its own.

Second, (at least on my setup) Explainer cannot automatically determine a suitable explainer for SVC, so you might want to call an appropriate explainer directly, e.g. KernelExplainer:

explainer = shap.KernelExplainer(model.predict)
  • How do you know what `model` object is without seeing what `create_model` is? – Sergey Bushmanov Feb 04 '22 at 20:45
  • It's right in the error message given in the question: Model: SVC(C=300, probability=True). I also set up an SVC model with the same parameters to bypass ambiguity of `create_model` function and arrived at the same error given the rest of the provided code. – Always Right Never Left Feb 05 '22 at 13:27
  • I have tried this method but I got stuck for hours in the progress bar. I will edit the question to add the create_model function and the progress bar. – DataDev98 Feb 06 '22 at 06:26
  • `KernelExplainer` will do computations for every row, so if your dataset is large there's not much you can do – Always Right Never Left Feb 06 '22 at 09:44