Comments (4)
I have encountered the same issue - with multiclass output, the summary_plot function generates interaction plot while the summary bar plot is expected.
I manually fixed this issue by going to their source code and change the data type of their TreeExplainer output from numpy array to list.
Here is what I did in detail: I went to https://github.com/shap/shap/blob/master/shap/explainers/_tree.py and commented lines 515-516. After that, I successfully generated the summary plot with multi-class output.
This error was due to the change in version 0.45.0 - they changed the output from list to numpy array, as can be seen in lines 410-411 of file https://github.com/shap/shap/blob/master/shap/explainers/_tree.py, so I reversed this change to fix the issue.
from shap.
It is not XGBoost-specific, as I have the same problem with SHAP values derived from CatBoost and LightGBM models. It is related to shap.summary_plot.
from shap.
Well spotted! I think for the majority of cases, a shortcut with a C++ implementation of Tree SHAP is used, so these 2 lines need to be commented out too (the same data transformation as in the lines you pointed to):
Commenting these lines out most likely has some side effects, but without these lines the SHAP summary plot indeed works for multi-class classification models. Thanks!
from shap.
I encountered the same problem, and switching back to version 0.44.1 resolved it for me.
Below is a straightforward code to demonstrate the issue:
# Create a synthetic dataset
X, y = make_classification(n_samples=100, n_features=5, n_informative=3, n_redundant=1, n_clusters_per_class=1, n_classes=3, random_state=42)
features = [f"Feature {i}" for i in range(X.shape[1])]
X = pd.DataFrame(X, columns=features)
# Train a RandomForest model
model = RandomForestClassifier(n_estimators=50, random_state=42)
model.fit(X, y)
# Create the SHAP Explainer
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X)
# Plot SHAP values for each class
shap.summary_plot(shap_values, X, plot_type="bar", class_names=['Class 0', 'Class 1', 'Class 2'])
Here are the screenshots for both versions:
from shap.
Related Issues (20)
- Questions: question about SamplingExplainer HOT 1
- BUG: SHAP values calculated using CPU differ from SHAP values calculated using GPU HOT 5
- BUG: TypeError: ufunc 'isfinite' not supported for the input types HOT 4
- BUG: Additivity check failed HOT 1
- When plotting the shap text it is showing an extra letter(Ġ) before every word. HOT 1
- Demangle pytorch and tensorflow dependencies
- ENH: Python 3.13 Support
- TypeError: In v0.20, force plot now requires the base value as the first parameter! Try shap.plots.force(explainer.expected_value, shap_values) or for multi-output models try shap.plots.force(explainer.expected_value[0], shap_values[0]). HOT 1
- Key not found with shap.TreeExplainer and XGBRegressor HOT 1
- BUG: Unable to Generate SHAP values for a dataframe containing text data trained on lstm model HOT 2
- BUG: Error with SHAP Partial Dependence Plot: ValueError: DataFrame.dtypes for data must be int, float, bool or category
- ENH: integrated gradients
- Support tf 2.16 and keras 3 HOT 4
- BUG: shap.plots.bar(shap_values) TypeError
- BUG: Custom masker offset is not working properly
- BUG: AssertionError, the SHAP explanations do not sum up to the model's output!
- BUG: Background dataset subsampling HOT 4
- BUG: AttributeError: 'tuple' object has no attribute 'as_list' (tensorflow 2.15.0) HOT 2
- [Meta-issue] Release 0.46.0
- [Meta-issue] Increase test coverage
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shap.