Fixing list type when using max_features param in plot()#19
Merged
iancovert merged 1 commit intoiancovert:masterfrom Jun 16, 2023
Merged
Fixing list type when using max_features param in plot()#19iancovert merged 1 commit intoiancovert:masterfrom
iancovert merged 1 commit intoiancovert:masterfrom
Conversation
When calling `plot()` with the `max_features` parameter, it crashes with the following error:
```
TypeError Traceback (most recent call last)
script.py()
----> 1 sage.plot(sage_values, feature_names=list(X_test.columns), max_features=20)
File c:\<redacted>\Anaconda3\envs\lumc\lib\site-packages\sage\plotting.py:85, in plot(explanation, feature_names, sort_features, max_features, orientation, error_bars, confidence_level, capsize, color, title, title_size, tick_size, tick_rotation, label_size, figsize, return_fig)
83 else:
84 assert 0 < confidence_level < 1
---> 85 std = std * norm.ppf(0.5 + confidence_level / 2)
87 # Make plot.
88 fig = plt.figure(figsize=figsize)
TypeError: can't multiply sequence by non-int of type 'numpy.float64'
```
This change casts the `std` variable as `np.array` when `max_features` is set, to fix this issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When calling
plot()with themax_featuresparameter, it crashes with the following error:This change casts the
stdvariable asnp.arraywhenmax_featuresis set, to fix this issue.