forcing decision tree use specific features first
My goal it to force some feature used firstly to split tree. Below, the function splitted 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)
Topic decision-trees
Category Data Science