interpretml / interpret-community

Interpret Community extends Interpret repository with additional interpretability techniques and utility functions to handle real-world datasets and workflows.

Home Page:https://interpret-community.readthedocs.io/en/latest/index.html

Repository from Github https://github.cominterpretml/interpret-communityRepository from Github https://github.cominterpretml/interpret-community

numpy boolean subtract, the `-` operator, is not supported, use the bitwise_xor, the `^` operator, or the logical_xor function instead.

moisesdiaz-ds opened this issue · comments

When i try to run this code:
from interpret_community.widget import ExplanationDashboard
ExplanationDashboard(global_explanation, model, dataset=test.iloc[:,:-1], true_y=test.iloc[:,-1])

i am getting this error:
numpy boolean subtract, the - operator, is not supported, use the bitwise_xor, the ^ operator, or the logical_xor function instead.

I already tried to change the type of the target variable to: "category" or np.bool or np.float32
But none of it worked

@firemoises sorry about the trouble you are having. First, please use the ExplanationDashboard from raiwidgets instead of interpret_community:

from raiwidgets import ExplanationDashboard
...

Please see the github repository for more information:
https://github.com/microsoft/responsible-ai-widgets

The ExplanationDashboard in interpret-community (this github) is getting deprecated, this repo will only contain the interpretability library/wrappers.

Could you point to the notebook that is having this issue? Is this your own notebook or an example notebook on this github repository? Also what is the full stack trace for the error message? Our current tests are passing so I'm not sure why running the explanation dashboard is failing.

Thanks for the reply!

Even using from raiwidgets import ExplanationDashboard i am still getting the same error

I am using my own notebook

Here is the full error:

`TypeError Traceback (most recent call last)
in
1 from raiwidgets import ExplanationDashboard
2
----> 3 ExplanationDashboard(global_explanation, model, dataset=train.iloc[:,:-1], true_y=train.iloc[:,-1])

~\anaconda3\lib\site-packages\raiwidgets\explanation_dashboard.py in init(self, explanation, model, dataset, true_y, classes, features, public_ip, port, locale)
47 public_ip=None, port=None, locale=None):
48 """Initialize the ExplanationDashboard."""
---> 49 self.input = ExplanationDashboardInput(
50 explanation, model, dataset, true_y, classes, features)
51

~\anaconda3\lib\site-packages\raiwidgets\explanation_dashboard_input.py in init(self, explanation, model, dataset, true_y, classes, features)
56 # List of explanations, key of explanation type is "explanation_type"
57 if explanation is not None:
---> 58 self._mli_explanations = explanation.data(-1)["mli"]
59 else:
60 self._mli_explanations = None

~\anaconda3\lib\site-packages\interpret_community\explanation\explanation.py in data(self, key)
825 :rtype: dict
826 """
--> 827 parent_data = super().data(key=key)
828 if key is None:
829 return self._global_data(parent_data)

~\anaconda3\lib\site-packages\interpret_community\explanation\explanation.py in data(self, key)
585 perf_list = []
586 for i in range(0, num_rows):
--> 587 data_dict = self._local_data(parent_data, key=i)
588 data_dicts.append(data_dict)
589 perf_list.append(data_dict[InterpretData.PERF])

~\anaconda3\lib\site-packages\interpret_community\explanation\explanation.py in _local_data(self, parent_data, key)
561 # available currently, using predicted instead for now
562 if _DatasetsMixin._does_quack(self) and not _DatasetsMixin._is_reference(self):
--> 563 parent_data[InterpretData.PERF] = self._perf_dict(self._eval_y_predicted, self._eval_y_predicted, key)
564 if isinstance(self._eval_data, DatasetWrapper):
565 eval_data = self._eval_data

~\anaconda3\lib\site-packages\interpret_community\explanation\explanation.py in _perf_dict(self, y, y_hat, i)
523 di["residual"] = int(y[i] == y_hat[i])
524 else:
--> 525 di["residual"] = y[i] - y_hat[i]
526 return di
527

TypeError: numpy boolean subtract, the - operator, is not supported, use the bitwise_xor, the ^ operator, or the logical_xor function instead.`

@firemoises can you label encode y_test to be 0 or 1? Might it be that the dashboard cannot render non-numeric types for y.

Regards,

`
#from interpret_community.widget import ExplanationDashboard
from raiwidgets import ExplanationDashboard

ExplanationDashboard(global_explanation, model, dataset=test.iloc[:,:-1], true_y=test.iloc[:,-1].astype(int))
`

Hi i just did, but i am still getting the same error

@firemoises sorry, I was on vacation last week. I think this is a simple bug that needs to be fixed for handling label columns with boolean values. I will send out a fix this week.

@firemoises I was able to reproduce the issue and I've sent a PR to fix the issue here:

#434

Once reviewed and merged, I will release another version of interpret-community with the fix. Thank you for your patience!

@firemoises closing issue as PR has been merged. This will be in the next interpret-community release (0.19.3 or 0.20.0 depending on whether we decide to do another patch release or a minor release). I think we can try to release in a week or so (I just did a new release today for another bug fix before this PR was merged).

i have the same error

commented

i have the same error

Were you able to solve the problem? I also have the same problem. I checked the same version of all libraries on Linux (deb) and the code is running with no issue. But here on macOS (M1), I am getting the same error as you.

'''if an array1 and array2 does contains a boolens (True or False ), there is no means of array1 - array2, you need to perform morgan's laws with XOR or ^ as in logic mathematic, so check out if your arrays contains bool types'''
for element1, element2  in zip(array1, array2):
      if element1 in [False, True] or  element2 in [False, True]:
             raise TypeError('you cannot add or substract arrays')
# if the error araise you can convet the bools to zeros and ones then you can use - operation

def convert_bool(boool):
      if boool==True:
        return 1
      else :return 0
import numpy as np
array1=np.array([element for element in array1 if not isinstance(element, bool)  else convert_bool(element)]
array2=np.array([element for element in array1 if not isinstance(element, bool)  else convert_bool(element)]
array1-array2