parrt/dtreeviz

tree visualization issue with DecisionTreeClassifiers class of PySpark MLLIB

Closed this issue · 8 comments

Hi, I'm runnning your example notebook "dtreeviz_spark_visualisations.ipynb". To install dtreeviz I run from inside this notebook the code "pip install dtreeviz[pyspark]". No warning from this code, everything seems ok. After executing as suggested "%restart_python", I run the all the code in the notebook to generate the tree and till the code
"viz_model = dtreeviz.model(tree_model_classifier,
X_train=dataset[features], y_train=dataset[target],
feature_names=features,
target_name=target, class_names=["perish", "survive"])"

everything is still OK! When I run the code "viz_model.view(fancy=False,fontname="monospace") to visualize the tree graph, the only thing I get is "<dtreeviz.utils.DTreeVizRender at 0x7fe5a1b6e850>". Sorry, I'm new at using dtreeviz and I can't manage this issue. Can yoy help me? Thank you so much!

Sorry, after writing my previous comment, I found out that that the problem is probably about my Graphviz installation (both Linux and Windows, both Jupyter Notebook and Spyder). I say that because in any case, after importing Graphviz, I can create the dot.source (the Round table example: // The Round Table
digraph "round-table" {
A [label="King Arthur"]
B [label="Sir Bedevere the Wise"]
L [label="Sir Lancelot the Brave"]
A -> B
A -> L
B -> L [constraint=false]
}
but I cannot execute the dot. This is the message (the same on Linux and Window) "ExecutableNotFound: failed to execute WindowsPath('dot'), make sure the Graphviz executables are on your systems' PATH". Consider that I'm sure that Graphviz is installed in both environments and it seems useless sys.path.append the directory Graphviz is installed in. This thing is driving me crazy!

Hi @MaxSaputo, did you follow the instalation steps:
https://github.com/parrt/dtreeviz?tab=readme-ov-file#installation

I do remember that people encounter these types of error in the past, but it's been a long time ago.

Maybe you can search through issue history today check if somebody else got this error

Hi Tudor, thank you so much for your directions! I managed to fix the problem about Graphviz on my Window 11 Pro client and Pyhton with Spyder, just right reviewing the instruction of Graphviz user documentation (https://graphviz.readthedocs.io/en/stable/manual.html) - Installation section: reviewing more carefully, I noticed that after installing Graphviz on Pyhton with pip install, a further installation is required that's a working installation of Graphviz (this is defined the only DEPENDENCY). In this section is present a link from which many installation for Windows 64 bit are available (I choosed [graphviz-12.1.0 (64-bit) EXE installer]). Now I understood why in this section they say "After installing Graphviz, make sure that its bin/ subdirectory containing the dot layout command for rendering graph descriptions is on your systems’ PATH". I have stupidly searched for many days a subdirectory "bin" in my Python installation but this subdirectory is created by the second installation (the only DEPENDENCY) which is as far as I can understand a pure Window application and not related to Python. So , after installing the DEPENDENCY , launching Spyder and adding to my Python searching path the sub dir "bin" (os.environ["PATH"] += os.pathsep + r"C:\Program Files\Graphviz\bin") magically both Graphiz and Dtreeviz showed their wonderful graphs (the former simply digiting the name of a Digraph instance , the second with the view() method. Now I have to fix the same problem for a Python installation on a Databricks cluster: do you think that I have I to follow the same steps as I had for Window? Thank you so much again!

Happy that you managed to fix it on your laptop.

Give it a try on databricks also, not sure what OS they are using. If you have the same issues, maybe you have the rights to make the same installations there from CLI.

I know in general that people are using dtreeviz in aws notebooks with no issue.

@MaxSaputo could we close this issue?

Hi Tudor , sure, yes we can and many thanks!