更新时间:2022-10-27 09:26:38
是的,使用scikit-learn构建这样的树是正确的。
p>主要原因是这是一棵三叉树(最多有三个孩子的节点),但是 scikit-learn仅实现二叉树 -节点完全有两个或没有子节点:
cdef类树:
二进制的基于数组的表示形式
...
但是,有可能获得等效的二叉树形式
Outlook == Sunny
true =>湿度==高
true => ;否
false =>是
false => Outlook ==阴险
true =>是
false =>风==强
true = >否
fa lse =>是
There is well-know problem in Tom's Mitchell Machine Learning book to build decision tree based on the following data, where Play ball is the target variable.
The resulting tree is following
I wonder whether it's possible to build this tree with scikit-learn. I found several examples where decision tree can be depicted as
export_graphviz(clf)
Source(export_graphviz(clf, out_file=None))
However it looks like scikit doesn't work well with categorical data, the data has to be binarized into several columns. So as result, it is impossible to build the tree exactly as in the picture. Is it correct?
Yes, it is correct that it is impossible to build such a tree with scikit-learn.
The primary reason is that this is a ternary tree (nodes with up to three children) but scikit-learn implements only binary trees - nodes have exactly two or no children:
cdef class Tree:
"""Array-based representation of a binary decision tree.
...
However, it is possible to get an equivalent binary tree of the form
Outlook == Sunny
true => Humidity == High
true => no
false => yes
false => Outlook == Overcast
true => yes
false => Wind == Strong
true => no
false => yes