JuliaAI / DecisionTree.jl

Julia implementation of Decision Tree (CART) and Random Forest algorithms
Other
355 stars 102 forks source link

How to plot a decision tree (using a graphics package) #147

Open roland-KA opened 2 years ago

roland-KA commented 2 years ago

Is there a possibility to plot a decision tree using Plots.jl (or some other graphics package)?

I'm using MLJ and the only means to visualize a decision tree seems to be report(mach).print_tree(n) where mach is the trained machine.

If there is no such possibility: How can I access the tree (data structure) directly in MLJ?

roland-KA commented 2 years ago

Thanks, btw, for your advocacy at AbstractTrees.jl 🙏🏾

Well, thanks to you for your support! I don't think it would have worked without that.

If you still feel otherwise, I'd suggest a separate package, rather than in some MLJ package

The second question above (about placing the plot recipe) was not about a temporary package but about the final solution. I.e. I wanted to know, where I should put the plot recipe as it would be used in the future (because I can start now working on that).

It seems that you would suggest also for that solution a separate new package in my repo which I would register then?

In order to test that package under "real world conditions", I will need the abstract type AbstractNode. To do these tests before the type will be available from AbstractTrees.jl, I thought about creating a temporary package containing the following few lines of code (just for testing):

module AbstractNodeType

export AbstractNode
abstract type AbstractNode

end

It won't be necessary at all, if the next release of AbstractTrees.jl appears soon (enough).

ablaom commented 2 years ago

Yes, you're right, I completely misunderstood. 😳

Yes, a separate package for the recipe sounds good to me. You could own that or move it to JuliaAI as you wish.

ablaom commented 1 year ago

@roland-KA AbstractNode is now at AbstractTrees.jl 0.4.3 just released 🥳

roland-KA commented 1 year ago

Wow, that's great news 🤗.

Unfortunately I've been quite busy during the last few weeks, so I couldn't start to create the package for the plot recipe as intended. But November looks promising 😊.

roland-KA commented 1 year ago

Hi @ablaom, sorry for the delay. But now I have a package for the plot recipe ready in my repo: https://github.com/roland-KA/TreeRecipe.jl.

Apart from that, I've created a PR for DecisionTree.jl in order to use the new AbstractTrees.AbstractNode.

Could you perhaps have a look on both and tell me, if this is the right way to go?

roland-KA commented 1 year ago

Hi @sylvaticus, I've just created a PR for BetaML.jl in order to make it work with the TreeRecipe.jl I've created in the meantime. It uses the new abstract type AbstractNode from the AbstractTrees.jl-package.

There is an example on how to plot a BetaML decision tree using the recipe in roland-KA/TreeRecipe.jl/test/testBetaMLtrees.jl.

Note: TreeRecipe.jl isn't yet a registered package. So it has to be loaded currently from roland-KA/TreeRecipe.jl.

Sorry for leaving your package so long in limbo. But now it should work!

ablaom commented 1 year ago

@roland-KA Thanks for you patience. Just back from leave.

Looking awesome. Merged your DecisionTree PR: https://github.com/JuliaRegistries/General/pull/72785

Posted suggestions for new package at https://github.com/roland-KA/TreeRecipe.jl/issues/1