'How do I change the leaf label of a decision tree in Sklearn?
I need to relabel a leaf in a decision tree to influence predictions, but I can't find an attribute label in the tree. If the label was "+", I need to change it to "-" and vice versa. Do you know how I can do this?
Solution 1:[1]
I find the solution. I need to modify the "clf.tree_.value". This is an array that contains the number of samples for each class and is used for prediction. For example, if I have for a leaf the array [10., 5.]. I have 10 elements for class 0 and 5 for class 1. and the leaf will predict the class 0 (the majority class). So for relabel, I reverse the elements and I get [5., 10.]. So now, the classifier will predict the class 1 (+)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
