k_ug
k_ug

Reputation: 43

Edit scikit-learn decisionTree

I would like to edit sklearn decisionTree, e.g. change conditions or cut node/leaf etc.

But there seems to be no functions to do that, if I could export to a file, edit it to import.

How can I edit decisionTree?

Environment:

Upvotes: 3

Views: 3603

Answers (2)

zemekeneng
zemekeneng

Reputation: 1725

Even though the docs say that the splitter kwarg for DecisionTreeClassifier is a string, you could give it a class as well. Evidence:

https://github.com/scikit-learn/scikit-learn/blob/412996f/sklearn/tree/tree.py#L353-L360

Looks like you could subclass one of the Splitter classes found here:

https://github.com/scikit-learn/scikit-learn/blob/0.17.X/sklearn/tree/_splitter.pyx

And do:

my_decision_tree = sklearn.tree.DecisionTreeClassifier(splitter=mySplitter)

Upvotes: 5

Grainier
Grainier

Reputation: 1654

If you are thinking of editing a model, I don't think there's an easy way of doing this. There's been discussions on exporting (rather visualising) the rule set [1], [2], but not on importing the rule set. However, what's the point of manually trying to edit the rule set, when it fits for the most optimal solution? Then again if you really know the conditions, you can simply use a set of nested if-else conditions without using scikit-learn at all.

If you need to change the Impl of the splitter, you can do as @zemekeneng suggested.

Upvotes: 1

Related Questions