I see python visualisation of tree using Graphviz whch is simple and only few lines.
>>> from sklearn.datasets import load_iris
>>> from sklearn import tree
>>> clf = tree.DecisionTreeClassifier()
>>> iris = load_iris()
>>> clf = clf.fit(iris.data, iris.target)
>>> tree.export_graphviz(clf,out_file='tree.dot')
How to do the same in Julia using sklearn and graphviz. I see a tree structure in Julia but I want to visualise it.
1 Like
Using ScikitLearn.jl and PyCall.jl
using ScikitLearn
using RDatasets: dataset
@sk_import tree: (DecisionTreeClassifier, export_graphviz)
iris = dataset("datasets", "iris");
clf = fit!(DecisionTreeClassifier(), convert(Matrix{Float64}, iris[[:SepalLength, :SepalWidth, :PetalLength, :PetalWidth]]), iris[:Species])
export_graphviz(clf,out_file="tree.dot")
You can view the dot file using eg GraphViz. Also check out DecisionTree.jl for a native way of doing the same thing, though it doesn’t support graph visualization at the moment. Would be a nice PR.
1 Like
GraphViz.jl is currently broken with Julia 1.1
See https://github.com/Keno/GraphViz.jl/issues/33
It needs some care.
1 Like
It seems open source has provided a wonderful opportunity for the first one who needs GraphViz to give it some much needed care <3
1 Like
I was going to ask if I can visual a DecisionTree.jl model. I can’t seem to find it in the library documtation how to visualise a tree.