3
我的目标是确定在决策树中两个样本分开的深度。在开发版本scikit学习,你可以使用decision_path()
方法来识别最后的共同节点:scikit-learn决策树节点深度
from sklearn import tree
import numpy as np
clf = tree.DecisionTreeClassifier()
clf.fit(data, outcomes)
n_nodes = clf.tree_.node_count
node_indicator = clf.decision_path(data).toarray()
sample_ids = [0,1]
common_nodes = (node_indicator[sample_ids].sum(axis=0) == len(sample_ids))
common_node_id = np.arange(n_nodes)[common_nodes]
max_node = np.max(common_node_id)
有没有一种方法来确定在树内的什么深度发生max_node
,可能与clf.tree_.children_right
和clf.tree_.chrildren_left
?