Hi!
I am using a scikit-learn DecissionTreeClassifier on a 3 class dataset.
After I fit the classifier I access all leaf nodes on the tree_ attribute
in order to get the amount of instances that end up in a given node for
each class.
clf = tree.DecisionTreeClassifier(max_depth=5)
clf.fit(X, y)
# lets assume there is a leaf node with id 5
print clf.tree_.value[5]
This will print out:
>>> array([[ 0., 1., 68.]])
but ... how do I know which position in that array belongs to which class ?
The classifier has a classes_ attribute which is also a list
>>> clf.classes_
array(['CLASS_1', 'CLASS_2', 'CLASS_3'], dtype=object)
Maybe index 1 on the value array matches the class on index 1 of the
classes array and so on?
By the way, first created a post in stack overflow, but the only answer I
got was wrong so I thought I would get a better chance if I asked here.
Here is the link :
http://stackoverflow.com/questions/26207451/scikit-learn-decisiontreeclassifier-tree-value-mapping-to-class
I hope u don't take this a double posting... and if u do, sorry then.
Nemi.
------------------------------------------------------------------------------
Slashdot TV. Videos for Nerds. Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general