shap

SHAP KernelExplainer using PipeLine

SHAP KernelExplainer using PipeLine Question: I have a problem where I want to use pipeline (with OHE as preprocess and simple Linear Regression as model) with SHAP tools. As for the data, here are my data (I’m using my modified version of bike sharing dataset): bike_data=pd.read_csv("bike_outlier_clean.csv") bike_data[‘season’]=bike_data.season.astype(‘category’) bike_data[‘year’]=bike_data.year.astype(‘category’) bike_data[‘holiday’]=bike_data.holiday.astype(‘category’) bike_data[‘workingday’]=bike_data.workingday.astype(‘category’) bike_data[‘weather_condition’]=bike_data.weather_condition.astype(‘category’) bike_data[‘season’] = bike_data[‘season’].map({1:’Spring’, 2:’Summer’, …

Total answers: 1

shap : SystemError: initialization of _internal failed without raising an exception

shap : SystemError: initialization of _internal failed without raising an exception Question: I am using a SVC to predict a target. I am tryring to use shap to get features importance. but it fails. here is my simple code that I copied from the official doc of shap : import shap svc_linear = SVC(C=1.2, probability=True) …

Total answers: 2

Why is base value in shap score plot different for different inputs?

Why is base value in shap score plot different for different inputs? Question: I am trying to implement shap score from shap python package following the example in the same link. data[‘text’][:3] gives me tbree examples: [‘i didnt feel humiliated’, ‘i can go from feeling so hopeless to so damned hopeful just from being around …

Total answers: 1

How to get non-bar SHAP plot for LightGBM

How to get non-bar SHAP plot for LightGBM Question: I have trained a lightGBM model using this code: from flaml import AutoML #Select Hyper-Parameters automl_final = AutoML() automl_final.fit( X_train, y_train, estimator_list=["lgbm"],#,"xgboost"], task="classification", metric="roc_auc", eval_method="cv", n_splits=3, time_budget=30, sample=True, append_log=True, log_type="all", model_history=True, log_training_metric=True, verbose=3, seed=1234, early_stop=True ) Then I have generated a SHAP bar plot using this …

Total answers: 2

Permission denied when calling SHAP

Permission denied when calling SHAP Question: I am using Jupyter Notebook and my OS is windows. I wanted to call shap library using the code !pip install shap but I got this error: ModuleNotFoundError: No module named ‘shap’ I have already installed shap in windows Command Prompt by pip install shap After that I tried …

Total answers: 1

How to plot the SHAP values log loss with index as x-axis

How to plot the SHAP values log loss with index as x-axis Question: Trying to plot the shap-values of a given feature w.r.t log-loss and setting the x-axis to be the index. as the attached image. While from the documentation only finding the scatter & dependence plot which are plotting x-axis the feature values not …

Total answers: 1

How to get SHAP values for each class on a multiclass classification problem in python

How to get SHAP values for each class on a multiclass classification problem in python Question: I have the following dataframe: import pandas as pd import random import xgboost import shap foo = pd.DataFrame({‘id’:[1,2,3,4,5,6,7,8,9,10], ‘var1’:random.sample(range(1, 100), 10), ‘var2’:random.sample(range(1, 100), 10), ‘var3’:random.sample(range(1, 100), 10), ‘class’: [‘a’,’a’,’a’,’a’,’a’,’b’,’b’,’c’,’c’,’c’]}) For which I want to run a classification algorithm in …

Total answers: 4

SHAP with a self-defined function

SHAP with a self-defined function Question: For example, I have a self defined function def f(x): ## x is a 3D vector return x[0] + 2*x[1] – 3*x[2] data = np.random.rand(10,3) explainer = shap.Explainer(f) shap_values = explainer(data) The last line gives the following error TypeError Traceback (most recent call last) /tmp/ipykernel_16518/3954986287.py in <module> —-> 1 …

Total answers: 2

Retrieve Model Results for Shapley values from GridSearch CV

Retrieve Model Results for Shapley values from GridSearch CV Question: I have tuned a model using GridSearchCV. Now I would like to calculate the Shapley values and visualize them. The difficulty is that the shap package excepts a model, not the GridSearch Results. Likewise it does not like when I pass it the best_estimator_ attribute. …

Total answers: 1

How to solve the ERROR: usage: _jb_pytest_runner.py error running the SHAP test-cases with PyCharm?

How to solve the ERROR: usage: _jb_pytest_runner.py error running the SHAP test-cases with PyCharm? Question: I cannot get around this error while trying to run the shap test-cases with PyCharm: /home/user/shap/venv/bin/python /home/user/Desktop/pycharm-community-2021.1.2/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py –path /home/user/shap/tests Testing started at 10:51 a.m. … Launching pytest with arguments /home/user/shap/tests in /home/user/shap/tests ERROR: usage: _jb_pytest_runner.py [options] [file_or_dir] [file_or_dir] […] _jb_pytest_runner.py: …

Total answers: 2