Model.shapExplainer

In [ ]:
Model.shapExplainer()

Creates the Model shapExplainer.

Returns

shap.Explainer : the shap Explainer.

Example

In [6]:
from verticapy.learn.linear_model import LinearRegression
model = LinearRegression(name = "public.logit_titanic")
model.drop()
model.fit("public.titanic", 
          ["age", "pclass", "fare"], 
          "survived")
explainer = model.shapExplainer()
type(explainer)

Out[6]:
shap.explainers._linear.Linear
In [11]:
import shap
import numpy as np

# Initialize the JS
shap.initjs()

# Getting shap Values
shap_values = explainer.shap_values(np.array([[30., 3, 50.]]))

# Visualize the first prediction's explanation
shap.force_plot(explainer.expected_value, 
                shap_values[0,:], 
                [30., 1, 50.],
                feature_names = ["age", "pclass", "fare"],
                out_names = "survived")
Out[11]:
Visualization omitted, Javascript library not loaded!
Have you run `initjs()` in this notebook? If this notebook was from another user you must also trust this notebook (File -> Trust notebook). If you are viewing this notebook on github the Javascript has been stripped for security. If you are using JupyterLab this error is because a JupyterLab extension has not yet been written.