1
$\begingroup$

I'm using Pima Indians Diabetes Database(https://www.kaggle.com/uciml/pima-indians-diabetes-database). I made predictions using XGboost and I'm trying to analyze the features using SHAP.

However when I use force_plot with just one training example(a 1x8 vector) it shows that my output is -2.02. This is a classification problem, I shouldn't be seeing such a value. I'm new in SHAP and I don't know what the problem is.

Here is my code:

import numpy as np
import xgboost as xgb
import sklearn as skl
import shap

dataset=np.loadtxt("diabetes.csv", delimiter=",")
X=dataset[:,0:8]
Y=dataset[:,8]
seed=7
test_size=0.33
X_train, X_test, y_train, y_test=skl.model_selection.train_test_split(X, Y, test_size=test_size, random_state=seed)

shap.initjs()
model=xgb.XGBClassifier()
model.fit(X_train, y_train)

predictions=model.predict(X_test)
accuracy=skl.metrics.accuracy_score(y_test, predictions)
print(accuracy*100)

explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X_train)
shap.force_plot(explainer.expected_value, shap_values[0,:].reshape(1, 8), X_train[0,:].reshape(1, 8))

Accuracy of my model is: 77,95.

Here is the result of my plot

$\endgroup$

1 Answer 1

1
$\begingroup$

The default link function is the identity, so you are seeing log-odds rather than probabilities. To see the probability, try adding link='logit' to your call of force_plot like so:

shap.force_plot(explainer.expected_value,
                shap_values[0,:].reshape(1, 8),
                X_train[0,:].reshape(1, 8),
                link='logit')

You can read more at the SHAP documentation site.

$\endgroup$
2
  • $\begingroup$ I did what you sad, I see 0.12 now as my output. Does it means my output is 0? $\endgroup$
    – J.Smith
    Aug 5, 2019 at 10:56
  • $\begingroup$ That would mean that the probability output by the model is 0.12. If you are using 0.5 as a cutoff, then your prediction is 0. But note that you can use any cutoff value that you'd like. This is what gives rise to the ROC curve and AUC metric. $\endgroup$
    – DKL
    Aug 6, 2019 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.