I ran into a divide by zero issue in _violin.py when nbins =1
I'm not sure when this situation occurs but the module halts and does not give enough information to resolve it with the data it is receiving or assign a color that does not compromise the output.
Minimal Reproducible Example
easy fix
#Edge case
# c = pl.get_cmap(color)(i / (
# nbins - 1)) if color in pl.cm.datad else color # if color is a cmap, use it, otherwise use a color
if nbins == 1:
c = pl.get_cmap(color)(0) if color in pl.cm.datad else color # use the start of the color map or the single color
else:
c = pl.get_cmap(color)(i / (nbins - 1)) if color in pl.cm.datad else color # if color is a cmap, use it, otherwise use a color
not sure if this is best
Traceback
Traceback (most recent call last):
File "/fnr/bart_py/./src/shap-gpu.py", line 266, in <module>
shap.plots.violin(
File "/home/m/.local/lib/python3.10/site-packages/shap-0.42.1-py3.10-linux-x86_64.egg/shap/plots/_violin.py", line 299, in violin
c = pl.get_cmap(color)(i / (
ZeroDivisionError: division by zero
Expected Behavior
No response
Bug report checklist
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest release of shap.
[ ] I have confirmed this bug exists on the master branch of shap.
[ ] I'd be interested in making a PR to fix this bug
Thanks for raising this issue.
Could you provide a more complete reproducible example ? Containing everything from imports to the line of the error, using data from shap.datasets or randomly generated data.
Issue Description
I ran into a divide by zero issue in _violin.py when nbins =1
I'm not sure when this situation occurs but the module halts and does not give enough information to resolve it with the data it is receiving or assign a color that does not compromise the output.
Minimal Reproducible Example
Traceback
Expected Behavior
No response
Bug report checklist
Installed Versions
shap==0.42.1