'Forcing tree to use some feature first
My goal it to force some feature used firstly to split tree. Below, the function spltted tree using feature_3 first. For instance, is there a way to force to use feature_2 first instead of feature_3 ?
from sklearn import datasets
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
iris = datasets.load_iris()
X = iris.data
y = iris.target
fit = DecisionTreeClassifier(max_leaf_nodes=3, random_state=0).fit(X,y)
text_representation = tree.export_text(fit)
print('Graph')
print(text_representation)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
