Rambatino / CHAID

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

Issue exporting tree graph #121

Closed Soumaya787 closed 3 years ago

Soumaya787 commented 3 years ago

Hello, I get the following error when i try to export the tree graph.

tree.render(path=None, view=False)

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-28-e8b3f601885a> in <module>
----> 1 tree.render(path=None, view=False)

C:\Users\Public\Anaconda3\lib\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)

C:\Users\Public\Anaconda3\lib\site-packages\CHAID\graph.py in render(self, path, view)
     75                     edge_label = "     ({})     \n ".format(', '.join(map(str, node.choices)))
     76                     g.edge(str(node.parent), str(node.node_id), xlabel=edge_label)
---> 77             g.render(path, view=view)
     78 
     79     def bar_chart(self, node):

C:\Users\Public\Anaconda3\lib\site-packages\graphviz\files.py in render(self, filename, directory, view, cleanup, format, renderer, formatter, quiet, quiet_view)
    236         relative to the DOT source file.
    237         """
--> 238         filepath = self.save(filename, directory)
    239 
    240         if format is None:

C:\Users\Public\Anaconda3\lib\site-packages\graphviz\files.py in save(self, filename, directory)
    198 
    199         log.debug('write %d bytes to %r', len(data), filepath)
--> 200         with io.open(filepath, 'w', encoding=self.encoding) as fd:
    201             fd.write(data)
    202             if not data.endswith(u'\n'):

OSError: [Errno 22] Invalid argument: 'trees\\2021-06-10 12:27:30.gv'

I tried one of the suggested workarounds but I get another error :



tree.render(path=os.getcwd()+"\\file.gv", view=False)

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
C:\Users\Public\Anaconda3\lib\site-packages\graphviz\backend.py in run(cmd, input, capture_output, check, encoding, quiet, **kwargs)
    163     try:
--> 164         proc = subprocess.Popen(cmd, startupinfo=get_startupinfo(), **kwargs)
    165     except OSError as e:

C:\Users\Public\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    853 
--> 854             self._execute_child(args, executable, preexec_fn, close_fds,
    855                                 pass_fds, cwd, env,

C:\Users\Public\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1306             try:
-> 1307                 hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   1308                                          # no special security

FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable

During handling of the above exception, another exception occurred:

ExecutableNotFound                        Traceback (most recent call last)
<ipython-input-33-da293a29d1d6> in <module>
----> 1 tree.render(path=os.getcwd()+"\\file.gv", view=False)

C:\Users\Public\Anaconda3\lib\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)

C:\Users\Public\Anaconda3\lib\site-packages\CHAID\graph.py in render(self, path, view)
     75                     edge_label = "     ({})     \n ".format(', '.join(map(str, node.choices)))
     76                     g.edge(str(node.parent), str(node.node_id), xlabel=edge_label)
---> 77             g.render(path, view=view)
     78 
     79     def bar_chart(self, node):

C:\Users\Public\Anaconda3\lib\site-packages\graphviz\files.py in render(self, filename, directory, view, cleanup, format, renderer, formatter, quiet, quiet_view)
    241             format = self._format
    242 
--> 243         rendered = backend.render(self._engine, format, filepath,
    244                                   renderer=renderer, formatter=formatter,
    245                                   quiet=quiet)

C:\Users\Public\Anaconda3\lib\site-packages\graphviz\backend.py in render(***failed resolving arguments***)
    221         cwd = None
    222 
--> 223     run(cmd, capture_output=True, cwd=cwd, check=True, quiet=quiet)
    224     return rendered
    225 

C:\Users\Public\Anaconda3\lib\site-packages\graphviz\backend.py in run(cmd, input, capture_output, check, encoding, quiet, **kwargs)
    165     except OSError as e:
    166         if e.errno == errno.ENOENT:
--> 167             raise ExecutableNotFound(cmd)
    168         else:
    169             raise

ExecutableNotFound: failed to execute ['dot', '-Kdot', '-Tpng', '-O', 'file.gv'], make sure the Graphviz executables are on your systems' PATH```

Thanks in advance
Rambatino commented 3 years ago

Hello!

Is graphviz in your path? I can see this error:

ExecutableNotFound: failed to execute ['dot', '-Kdot', '-Tpng', '-O', 'file.gv'], make sure the Graphviz executables are on your systems' PATH
Rambatino commented 3 years ago

Closing as stale