NorskRegnesentral / shapr

Explaining the output of machine learning models with more accurately estimated Shapley values
https://norskregnesentral.github.io/shapr/
Other
138 stars 32 forks source link

TypeError when running examples #346

Closed nikoltoll closed 1 year ago

nikoltoll commented 1 year ago

When I run an example, for instance sklearn_regressor.py, I get the following error in explain.py:

File c:\users\nikur\code\shapr\python\shaprpy\explain.py:30 n_combinations: int | None = None,

TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

martinju commented 1 year ago

I am not a python expert, but by googling this, it seems that it's an issue with Python versions pre 3.10, see e.g. https://github.com/tiangolo/typer/issues/371

The examples runs fine on my end with Python 3.11.3. I guess you are on 3.9 or earlier?

nikoltoll commented 1 year ago

Yes the Python version was the problem. I substituted all | by ‘or’, but then I got an error that explain returned four arguments instead of three. This was easily solved by adding a fourth argument. This turned out to be timing info coming from R. Now it works, thanks!

martinju commented 1 year ago

Great! Feel free to add a PR if you believe substituting | by or is a fix that works on more python versions.

Seems like I forgot to update some of the examples after expanding the output from the function call. Will fox that.