Skip to content

Comments

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

Merged
iancovert merged 1 commit intoiancovert:masterfrom
DenizY7:master
Jun 16, 2023
Merged

Fixing list type when using max_features param in plot()#19
iancovert merged 1 commit intoiancovert:masterfrom
DenizY7:master

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.

2 participants