Visualising a decision tree using GraphViz

package

#1

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.


#2

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.