On the current master branch, using the OP's example: In [7]: clf.tree_.weighted_n_node_samples Out[7]: array([ 50. , 15. , 35. , 16. , 14.1, 1.9, 0.7, 0.4, 0.3, 1.2, 19. , 3.1, 0.7, 0.4, 0.3, 2.4, 15.9, 0.3, 15.6])
On Sun, Aug 30, 2015 at 8:43 AM, Jacob Schreiber <jmschreibe...@gmail.com> wrote: > Trevor, those attributes are present while the tree is being built, but > are not kept in the final tree object. > > On Sun, Aug 30, 2015 at 7:15 AM, Trevor Stephens <trev.steph...@gmail.com> > wrote: > >> n_node_samples is the count of actual dataset samples in each >> node. weighted_n_node_samples is the same, weighted by the class_weight >> and/or sample_weight. >> >> On Sun, Aug 30, 2015 at 8:02 AM, Rex X <dnsr...@gmail.com> wrote: >> >>> DecisionTreeClassifier.tree_.n_node_samples is the total number of >>> samples in all classes of one node, and >>> DecisionTreeClassifier.tree_.value is the computed weight for each >>> class of one node. Only if the sample_weight and class_weight of this >>> DecisionTreeClassifier >>> is one, then this attribute equals the number of samples of each class of >>> one node. >>> >>> But for the general case with a given sample_weight and class_weight, is >>> there any attribute telling us the number of samples of each class >>> within one node? >>> >>> >>> import pandas as pd >>> from sklearn.datasets import load_iris >>> from sklearn import tree >>> import sklearn >>> >>> iris = sklearn.datasets.load_iris() >>> clf = tree.DecisionTreeClassifier(class_weight={0 : 0.30, 1: 0.3, >>> 2:0.4}, max_features="auto") >>> clf.fit(iris.data, iris.target) >>> >>> >>> # the total number of samples in all classes of each node >>> clf.tree_.n_node_samples >>> >>> # the computed weight for each class of each node >>> clf.tree_.value >>> >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> >>> _______________________________________________ >>> Scikit-learn-general mailing list >>> Scikit-learn-general@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general >>> >>> >> >> >> ------------------------------------------------------------------------------ >> >> _______________________________________________ >> Scikit-learn-general mailing list >> Scikit-learn-general@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general >> >> > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Scikit-learn-general mailing list > Scikit-learn-general@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/scikit-learn-general > >
------------------------------------------------------------------------------
_______________________________________________ Scikit-learn-general mailing list Scikit-learn-general@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/scikit-learn-general