Skip to content

Use shap.force_plot with the hiclass's explainer (the first parameter base value) #156

@RamSnoussi

Description

@RamSnoussi

Hi @mirand863
shap.force_plot function have a base value as parameter. This parameter equals to explainer.expected_value
how can I calculate expected_value with current definition of Explainer? what can i write in xxxxxxxxx ? below is my code:

from hiclass import LocalClassifierPerParentNode, Explainer
from sklearn.ensemble import RandomForestClassifier
import numpy as np
import shap
X_train = np.array([
    [40.7,  1. ,  1. ,  2. ,  5. ,  2. ,  1. ,  5. , 34.3],
    [39.2,  0. ,  2. ,  4. ,  1. ,  3. ,  1. ,  2. , 34.1],
    [40.6,  0. ,  3. ,  1. ,  4. ,  5. ,  0. ,  6. , 27.7],
    [36.5,  0. ,  3. ,  1. ,  2. ,  2. ,  0. ,  2. , 39.9],
])

Y_train = np.array([
    ['Gastrointestinal', 'Norovirus', ''],
    ['Respiratory', 'Covid', ''],
    ['Allergy', 'External', 'Bee Allergy'],
    ['Respiratory', 'Cold', ''],
])

test_sample = np.array([[35.5,  0. ,  1. ,  1. ,  3. ,  3. ,  0. ,  2. , 37.5]])

classifier = LocalClassifierPerParentNode(local_classifier=RandomForestClassifier(), replace_classifiers=False)
classifier.fit(X_train, Y_train)
explainer = Explainer(classifier, data=X_train, mode="tree")
explanations = explainer.explain(test_sample)
mask = {'class': 'Cold', 'level':1}
shap_values = explanations.sel(mask).shap_values
shap.force_plot( xxxxxxxxxxx, shap_values, test_sample, matplotlib=True, show=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions