每个功能的节点数-Python Scikit学习决策树

时间:2019-02-18 20:23:04

标签: python scikit-learn decision-tree

我正在使用scikit-learn来制作决策树,我需要知道每个功能部件具有的节点数以及每个节点的截止值。例如,在树中,我想知道“大小”变量在树中有多少个节点,或者“位置”变量在树中有多少个节点,如果可能,这些节点中的临界值是多少。

这是我的样本训练数据:

size,count,status,location,is_relevant
0.99,39.19,true,east,false
6.45,58.308,false,south,false
4.844,103.6,false,west,true
4.1,63.209,false,west,false
1.05,52.06,false,west,false

这是我的样本测试数据:

size,count,status,location,is_relevant
2.88,139.78,false,north,true
1.29,11.37,false,south,false
3.6,33.97,false,west,true
1.8,43.93,false,west,false
7.41,60.2,false,south,false

这是我用来制作树的代码:

training['location']=pd.Categorical(training.location).codes
testing['location']=pd.Categorical(testing.location).codes

y=training.loc[:,'is_relevant']
x=training.iloc[:, :-1]

from sklearn import tree
model = tree.DecisionTreeClassifier()
model=model.fit(x, y)
predictions = model.predict(testing.iloc[:, :-1])
print(model.tree_)
print(model.tree_.node_count)

我能够导出树并对其进行可视化,但是有太多的节点无法去计算我想要的功能的节点数。有命令吗?

谢谢

0 个答案:

没有答案