Rambatino / CHAID

A python implementation of the common CHAID algorithm
Apache License 2.0
150 stars 50 forks source link

CHAID tree to json #71

Closed asram6 closed 7 years ago

asram6 commented 7 years ago

Hi, I am trying to get the json string corresponding to the CHAID tree. I tried converting the CHAID tree to a treelib tree, and then the treelib package has a method to_json(). However, when I call to_json() on the treelib tree, I get the error:

File "C:\Program Files\Anaconda3\lib\site-packages\treelib\tree.py", line 226, in to_dict
    tree_dict = {ntag: {"children": []}}
  File "C:\Program Files\Anaconda3\lib\site-packages\CHAID\node.py", line 42, in __hash__
    return hash(self.__dict__)
TypeError: unhashable type: 'dict'

Is there any way I can solve this problem? Any tips would be appreciated. Thanks!

Rambatino commented 7 years ago

It means that there is no method on a node object that looks like:

def __dict__(self):
   # come code here
   pass

If you require it to be there, please submit a PR with the code and a spec and I can review it.

It isn't on our roadmap, so will have to be built by the community.

Actually, you'll have to add it to the Node and Split classes, not just Node.

Rambatino commented 7 years ago

Closing, as that's the solution. Please let me know if you need anymore help.