Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing list type when using max_features param in plot() #19

Merged
merged 1 commit into from
Jun 16, 2023

Conversation

DenizY7
Copy link
Contributor

@DenizY7 DenizY7 commented Jun 14, 2023

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.

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.
@iancovert iancovert merged commit d47001d into iancovert:master Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants