Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 778
karpan Avatar asked Nov 17 '22 02:11

karpan


1 Answers

you can install plugin called dotplugin by bzixilu, when you open the dot file, automatically the graph will shown next to it

like image 121
galios Avatar answered May 16 '23 07:05

galios