我可以用图函数将GBDT的结构导出到图像中
```javascript从sklearn.datasets导入load_iris
从滑雪板导入树
从sklearn.ensemble导入GradientBoostingClassifier
为了简单起见,将clf = GradientBoostingClassifier(n_estimators=1) #设置为1
iris = load_iris()
clf = clf.fit(iris.data,iris.target)
tree.exportgraphviz(clf.estimators0,0,out_file='tree.dot')
Check_call(“点”、“-Tpng”、“tree.dot”、“-o”、“tree.png”)
我想知道叶子上的value是什么?我怎样才能得到它们呢?
我尝试过apply和decision_function函数,两者都不起作用。
发布于 2017-11-26 19:19:56
您可以使用每个树的内部对象tree_及其属性访问其保留属性。export_graphviz正是使用这种方法。
考虑一下这段代码。对于每个属性,它在所有树节点上给出其值的数组:
print(clf.estimators_[0,0].tree_.feature)
print(clf.estimators_[0,0].tree_.threshold)
print(clf.estimators_[0,0].tree_.children_left)
print(clf.estimators_[0,0].tree_.children_right)
print(clf.estimators_[0,0].tree_.n_node_samples)
print(clf.estimators_[0,0].tree_.value.ravel())输出将是
[ 2 -2 -2]
[ 2.45000005 -2. -2. ]
[ 1 -1 -1]
[ 2 -1 -1]
[150 50 100]
[ 3.51570624e-16 2.00000000e+00 -1.00000000e+00]也就是说,树有3个节点,第一个节点比较了特性2和2.45等的值。
根节、左右叶的值分别为3e-16、2和-1。
这些值,虽然,并不明显的解释,因为树已经尝试预测梯度的GBDT损失函数。
https://stackoverflow.com/questions/47465274
复制相似问题