【发布时间】:2017-01-21 10:21:59
【问题描述】:
我的目标是确定决策树中两个样本分离的深度。在 scikit-learn 的开发版本中,您可以使用decision_path() 方法识别到最后一个公共节点:
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?
【问题讨论】:
标签: python scikit-learn decision-tree