<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi Adrin,</div><div><br></div><div>Thanks for the clarification. Is there a right way of letting DecisionTreeClassifier know that the first column can take both 0 or 1, but in the current dataset we are only using 0?</div><div><br></div><div>For example, we can let MultiLabelBinarizer know that we have three classes by instantiating it like this: MultiLabelBinarizer([1,2,3]).</div><div><br></div><div>I tried class_weight=[{0: 1, 1: 1}, {0: 1, 1: 1}, {0: 1, 1: 1}] but that doesn't work.<br></div><div><br></div><div>Thanks,</div><div>Pranav<br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Oct 8, 2018 at 2:32 PM Adrin <<a href="mailto:adrin.jalali@gmail.com">adrin.jalali@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi Pranav,</div><div><br></div><div>The reason you're getting that 
output is that your first column has a single value (1), and that 
becomes your "first" class, hence your first value in the rows you're 
interpreting.</div><div><br></div><div>To understand it better, you can try to check this code:</div><div><br></div><div>>>> from sklearn.preprocessing import MultiLabelBinarizer<br>>>> from sklearn.tree import DecisionTreeClassifier<br>>>> <br>>>> X = [[2, 51], [3, 20], [5, 30], [7, 1], [20, 46], [25, 25], [45, 70]]<br>>>> Y = [[2,3],[1,2,3],[1,2,3],[1,2],[1,2],[1],[1]]<br>>>> <br>>>> y = MultiLabelBinarizer().fit_transform(Y) + 40<br>>>> y[0, 1] = 0<br>>>> <br>>>> clf = DecisionTreeClassifier().fit(X, y)<br>>>> print(clf.tree_.value)<br>[[[1. 6. 0.]<br>  [1. 2. 4.]<br>  [4. 3. 0.]]<br><br> [[1. 2. 0.]<br>  [1. 0. 2.]<br>  [0. 3. 0.]]<br><br> [[0. 2. 0.]<br>  [0. 0. 2.]<br>  [0. 2. 0.]]<br><br> [[1. 0. 0.]<br>  [1. 0. 0.]<br>  [0. 1. 0.]]<br><br> [[0. 4. 0.]<br>  [0. 2. 2.]<br>  [4. 0. 0.]]<br><br> [[0. 2. 0.]<br>  [0. 0. 2.]<br>  [2. 0. 0.]]<br><br> [[0. 2. 0.]<br>  [0. 2. 0.]<br>  [2. 0. 0.]]]</div><br><br><div class="gmail_quote"><div dir="ltr">On Mon, 8 Oct 2018 at 20:53 Pranav Ashok <<a href="mailto:pranavashok@gmail.com" target="_blank">pranavashok@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>I have a multi-class multi-label decision tree learnt using DecisionTreeClassifier class. The input looks like follows:</div><div><br></div><div>X = [[2, 51], [3, 20], [5, 30], [7, 1], [20, 46], [25, 25], [45, 70]]</div><div>Y = [[1,2,3],[1,2,3],[1,2,3],[1,2],[1,2],[1],[1]]</div><div><br></div><div>I have used MultiLabelBinarizer to convert Y into <br><pre>[[1 1 1]
 [1 1 1]
 [1 1 1]
 [1 1 0]
 [1 1 0]
 [1 0 0]
 [1 0 0]]</pre></div><div><br></div><div>After training, the _tree.values looks like follows:<br></div><div><pre>array([[[7., 0.],
        [2., 5.],
        [4., 3.]],

       [[3., 0.],
        [0., 3.],
        [0., 3.]],

       [[4., 0.],
        [2., 2.],
        [4., 0.]],

       [[2., 0.],
        [0., 2.],
        [2., 0.]],

       [[2., 0.],
        [2., 0.],
        [2., 0.]]])<br><br><span style="font-family:arial,helvetica,sans-serif">I had the impression that the value array contains for each node, a list of lists [[n_1, y_1], [n_2, y_2], [n_3, y_3]] <br>such that n_i are the number of samples disagreeing with class i and y_i are the number of samples agreeing with <br>class i. But after seeing this output, it does not make sense.<br><br></span></pre><pre><span style="font-family:arial,helvetica,sans-serif">For example, the root node has the value [[7,0],[2,5],[4,3]]. According to my interpretation, this would mean<br>7 samples disagree with class 1; 2 disagree with class 2 and 5 agree with class 2; 4 disagree with class 3 and 3 agree with class 3.<br></span></pre><pre><span style="font-family:arial,helvetica,sans-serif">which, according to the input dataset is wrong.<br><br></span></pre><pre><span style="font-family:arial,helvetica,sans-serif">Could someone please help me understand the semantics of _tree.value for multi-label DTs?<br></span></pre></div></div></div></div></div>
_______________________________________________<br>
scikit-learn mailing list<br>
<a href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br>
</blockquote></div></div>
_______________________________________________<br>
scikit-learn mailing list<br>
<a href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br>
</blockquote></div>