Rambatino / CHAID

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

Continuous Column name arg & Plotting Tree #127

Closed arainboldt closed 2 years ago

arainboldt commented 2 years ago

Hi,

Great package, seems to be completely unique in the Python ecosystem, oddly enough. Really grateful for the contribution.

I'm running into two small problems.

First, the ContinuousColumn doesn't have a name arg. This breaks the API and also prevents splits from having names.

Second, I'm trying to visualize the tree and having trouble.

I've tried: This Tree(independent_cols, dependent_col).to_tree().to_graphviz() returns a NoneType, so I'm not sure how to plot it.

And this: Tree(independent_cols, dependent_col).render(path=name, view=True) and variations raises this error:

~/Library/Caches/pypoetry/virtualenvs/segmentation-creation-Qfvb1sdR-py3.8/lib/python3.8/site-packages/CHAID/tree.py in render(self, path, view)
    289 
    290     def render(self, path=None, view=False):
--> 291         Graph(self).render(path, view)

~/Library/Caches/pypoetry/virtualenvs/segmentation-creation-Qfvb1sdR-py3.8/lib/python3.8/site-packages/CHAID/graph.py in render(self, path, view)
     70             )
     71             for node in self.tree:
---> 72                 image = self.bar_chart(node)
     73                 g.node(str(node.node_id), image=image)
     74                 if node.parent is not None:

~/Library/Caches/pypoetry/virtualenvs/segmentation-creation-Qfvb1sdR-py3.8/lib/python3.8/site-packages/CHAID/graph.py in bar_chart(self, node)
     94 
     95         filename = os.path.join(self.tempdir, "node-{}.png".format(node.node_id))
---> 96         pio.write_image(fig, file=filename, format="png")
     97         return filename
     98 

~/Library/Caches/pypoetry/virtualenvs/segmentation-creation-Qfvb1sdR-py3.8/lib/python3.8/site-packages/plotly/io/_kaleido.py in write_image(fig, file, format, scale, width, height, validate, engine)
    266     # -------------
    267     # Do this first so we don't create a file if image conversion fails
--> 268     img_data = to_image(
    269         fig,
    270         format=format,

~/Library/Caches/pypoetry/virtualenvs/segmentation-creation-Qfvb1sdR-py3.8/lib/python3.8/site-packages/plotly/io/_kaleido.py in to_image(fig, format, width, height, scale, validate, engine)
    143     # ---------------
    144     fig_dict = validate_coerce_fig_to_dict(fig, validate)
--> 145     img_bytes = scope.transform(
    146         fig_dict, format=format, width=width, height=height, scale=scale
    147     )

~/Library/Caches/pypoetry/virtualenvs/segmentation-creation-Qfvb1sdR-py3.8/lib/python3.8/site-packages/kaleido/scopes/plotly.py in transform(self, figure, format, width, height, scale)
    159         if code != 0:
    160             message = response.get("message", None)
--> 161             raise ValueError(
    162                 "Transform failed with error code {code}: {message}".format(
    163                     code=code, message=message

ValueError: Transform failed with error code 525: Failed to execute 'getPointAtLength' on 'SVGGeometryElement': The element's path is empty.

Any guidance would be much appreciated.

Thanks!

Rambatino commented 2 years ago

Hi @arainboldt could you give me the top of your data so I can have a play?

Regarding the graphviz, have you installed the required libraries correctly as referenced in the README?

Rambatino commented 2 years ago

Closing due to inactivity