2017-11-24 4 views
0

私はthe tree.export_graphviz functionで画像にGBDTの構造をエクスポートすることができます。sklearn GBDTの葉の値は何ですか?どのように入手できますか?

を `` `のpython3

from sklearn.datasets import load_iris 
from sklearn import tree 
from sklearn.ensemble import GradientBoostingClassifier 

clf = GradientBoostingClassifier(n_estimators=1) # set to 1 for the sake of simplicity 
iris = load_iris() 

clf = clf.fit(iris.data, iris.target) 
tree.export_graphviz(clf.estimators_[0,0], out_file='tree.dot') 
check_call(['dot','-Tpng','tree.dot','-o','tree.png']) 

` ``

This is the obtained image.

私はvalue何であるか疑問に思いますリーフ?どのように入手できますか?

私はapplydecision_functionの機能を試しましたが、どちらも機能しません。

+0

値は、そのノードまたはその子ノードに属するサンプルの数です。 –

+0

@VivekKumar 'samples'の代わりに、' negative'になる 'value'を意味します。上記の画像を確認してください。 – user5594832

+0

Ohk。 'export_graphviz(...、proportion = True)'を実行すると何が得られますか?それらのサンプルの重量のように見えます。 –

答えて

0

個々のツリーの休暇プロパティには、内部オブジェクト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.45と特徴2の値、

ルートノードの値、左右のリーフは、それぞれ3e-162、及び-1あります。

これらの値は、ツリーがGBDT損失関数の勾配を予測しようとしているため、解釈が明白ではありません。

+0

'tree_'のすべての属性を取得するにはどうしたらいいですか? – user5594832

+0

'' 'dir(tree_)' ''はすべての属性のリストを生成します。https://docs.python.org/3/library/functions.html#dir –

関連する問題