1

デフォルトでは、scikit-learn DecisionTreeRegressorは、指定されたリーフノードのトレーニングセットからのすべてのターゲット値の平均を返します。scikit-learnのDecisionTreeRegressorのリーフノードでの値の分布の取得

しかし、予測されるリーフノードに含まれるトレーニングセットからターゲット値のリストを取得することに興味があります。これにより、分布を定量化し、標準偏差などの他のメトリックを計算することができます。

これはscikit-learnを使って可能ですか?

答えて

0

treeオブジェクトのapplyメソッドを探していると思います。 See here for the source。ここに例があります:

import numpy as np 
from sklearn.tree import DecisionTreeRegressor 

rs = np.random.RandomState(1234) 
x = rs.randn(10,2) 
y = rs.randn(10) 

md = rs.randint(1, 5) 
dtr = DecisionTreeRegressor(max_depth=md) 
dtr.fit(x, y) 

# The `tree_` object's methods seem to complain if you don't use `float32. 
leaf_ids = dtr.tree_.apply(x.astype(np.float32)) 

print leaf_ids 
# => [5 6 6 5 2 6 3 6 6 3] 

# Should be probably be equal for small depths. 
print 2**md, np.unique(leaf_ids).shape[0] 
# => 4, 4