I observed that scikit-learn clf.tree_.feature occasional return negative values. For example -2. As far as I understand clf.tree_.feature is supposed to return sequential order of the features. In case we have array of feature names
['feature_one', 'feature_two', 'feature_three']
, then -2 would refer to feature_two
. I am surprised with usage of negative index. In would make more sense to refer to feature_two
by index 1. (-2 is reference convenient for human digestion, not for machine processing). Am I reading it correctly?
Update: Here is an example:
def leaf_ordering():
X = np.genfromtxt('X.csv', delimiter=',')
Y = np.genfromtxt('Y.csv',delimiter=',')
dt = DecisionTreeClassifier(min_samples_leaf=10, random_state=99)
dt.fit(X, Y)
print(dt.tree_.feature)
Here is the output:
[ 8 9 -2 -2 9 4 -2 9 8 -2 -2 0 0 9 9 8 -2 -2 9 -2 -2 6 -2 -2 -2
2 -2 9 8 6 9 -2 -2 -2 8 9 -2 9 6 -2 -2 -2 6 -2 -2 9 -2 6 -2 -2
2 -2 -2]