The implementation of the classification tree in mathematics

I want to implement a simple classification tree (binary classification) using Mathematica.

How to implement a binary tree in Mathematica? Is there a symbol for this?

+2
source share
3 answers

Among the new objects in the MMA 8 are TreeGraph , CompleteKaryTree and KaryTree . The last two objects give binary trees by default. I do not know how effective they are for intensive computing, but they seem well suited to display classifications. And there are many predicates and options for manipulating and displaying them.

Here is an example of a classification tree from [Breiman, L. Classification and regression trees: Chapman and Hall / CRC, 1984.]. This applies to 3 questions to determine if a cardiac patient can die within 30 days if left untreated.

KaryTree[9, 2, VertexLabels -> {1 -> "Blood pressure > 91 ?", 2 -> "Age > 62.5?", 4 -> "Sinus tachycardia ?", 8 -> "< 30 days"}, EdgeLabels -> {1 \[UndirectedEdge] 2 -> "yes", 1 \[UndirectedEdge] 3 -> "no", 2 \[UndirectedEdge] 4 -> "yes", 2 \[UndirectedEdge] 5 -> "no", 4 \[UndirectedEdge] 8 -> "yes", 4 \[UndirectedEdge] 9 -> "no"}, ImagePadding -> 20] 

Classification graph

I would like to get rid of the two unused nodes on the right, but did not understand the elegant way to do this. So I think I will post a simple question about this on SO.

+2
source

I would say it depends on what you want to do with the data structure.

You can use the fact that Mathematica expressions themselves are trees.

If only leaf nodes are used, use nested lists, for example. {{1, {2, 3}}, 4} . If another node should also carry some data, you can use something like this:

 tree[1][tree[2][a, b], tree[3][c, tree[4][d, e]]] 

See the structure as follows:

 {{1, {2, 3}}, 4} // TreeForm tree[1][tree[2][a, b], tree[3][c, tree[4][d, e]]] // TreeForm 

The next question is how to implement algorithm X in such a data structure.

+2
source

Personally, I don’t quite know, but it seems that an article about the subject itself on the Wolfram website was found here . This may not answer your question, but hopefully you get some idea!

+1
source

All Articles