我正在尝试使用sklearn DecisionTreeClassifier中的'tree_'方法提取最深节点的规则。我很难理解模型中'children_left'和'children_right'数组的含义。有人能帮忙解释一下吗?
在Sklearn的示例中,http://scikit-learn.org/stable/auto_examples/tree/plot_unveil_tree_structure.html,它说:
但是它并没有解释 children_left 数组中数字的含义。
estimator = DecisionTreeClassifier(max_depth=4, random_state=0)
estimator.fit(X_train, y_train)
estimator.tree_.children_left
[6] array([ 1, 2, 3, 4, 5, -1, -1, 8, -1, -1, 11, 12, -1, -1, 15, -1, -1,
18, 19, 20, -1, -1, 23, -1, -1, 26, 27, -1, -1, 30, -1, -1, 33, 34,
35, 36, -1, -1, 39, -1, -1, 42, 43, -1, -1, 46, -1, -1, 49, 50, 51,
-1, -1, 54, -1, -1, 57, 58, -1, -1, 61, -1, -1])
tree_model.tree_.children_right
[7] array([32, 17, 10, 7, 6, -1, -1, 9, -1, -1, 14, 13, -1, -1, 16, -1, -1,
25, 22, 21, -1, -1, 24, -1, -1, 29, 28, -1, -1, 31, -1, -1, 48, 41,
38, 37, -1, -1, 40, -1, -1, 45, 44, -1, -1, 47, -1, -1, 56, 53, 52,
-1, -1, 55, -1, -1, 60, 59, -1, -1, 62, -1, -1])
在Sklearn的示例中,http://scikit-learn.org/stable/auto_examples/tree/plot_unveil_tree_structure.html,它说:
`# The decision estimator has an attribute called tree_ which stores the entire
# tree structure and allows access to low level attributes. The binary tree
# tree_ is represented as a number of parallel arrays. The i-th element of each
# array holds information about the node `i`. Node 0 is the tree's root. NOTE:
# Some of the arrays only apply to either leaves or split nodes, resp.`
但是它并没有解释 children_left 数组中数字的含义。