Visualising a decision tree using GraphViz



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 =,
         >>> tree.export_graphviz(clf,out_file='')                

How to do the same in Julia using sklearn and graphviz. I see a tree structure in Julia but I want to visualise it.


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])

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.