'visualise dot files in PyCharm
I have generated a dot file to visualise a decision tree using the code
import numpy as np
from sklearn.model_selection import train_test_split
import sklearn.tree
from sklearn.datasets import load_breast_cancer
cancer = load_breast_cancer()
X_train, X_test, y_train, y_test =train_test_split(cancer.data,cancer.target, stratify=cancer.target, random_state=42)
tree = sklearn.tree.DecisionTreeClassifier(random_state=0,max_depth=4)
tree.fit(X_train,y_train)
sklearn.tree.export_graphviz(tree,out_file="tree.dot",class_names=cancer.target_names,feature_names=cancer.feature_names,impurity=False, filled=True)
This successfully creates the tree.dot file. I can now generate a png file using the dot.exe utility of graphviz (https://graphviz.gitlab.io/_pages/Download/Download_windows.html)
from subprocess import check_call
check_call(['...PATH_TO_GRAPHVIZ/graphviz-2.38/release/bin/dot.exe','-Tpng','tree.dot','-o','tree.png'])
I would like to visualise the decision tree also within PyCharm. Is there a way to do this?
Solution 1:[1]
you can install plugin called dotplugin by bzixilu, when you open the dot file, automatically the graph will shown next to it
Solution 2:[2]
sudo apt install graphviz
File > Properties > External Tools
Press +
Fill out as below
To use..
Right click on dot file
External Tools > graphviz-dot-png
A png of the dot file will be generated, you can view this with Pycharm.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | galios |
Solution 2 | Duane |