Matias Eiletz
Matias Eiletz

Reputation: 429

How to force decision trees to use just integer numbers while evaluating

I'm doing a decision tree, and I would like to force the algorithm to evaluate conditions just in integer numbers. The features that I'm using, are discrete and integers, so it doesn't make sense that the tree shows "X <= 42.5" , so in this example case, I want the tree to show in the box one of the equivalents among "X < 43" or "X <= 42".

I need this to make the tree more understandable for non-technical people. It doesn't make sense to show "less than 15.5 songs", it should be less than 43 or less or equal than 42.

I tried changing the types of the columns of the source tables, and they are all int64, and the problem persists.

Code I'm using:

clf = tree.DecisionTreeClassifier(criterion='gini',
                                  max_depth=2,
                                  splitter='best')

clf = clf.fit(users_data, users_target)

So far I didn't find any parameters or anything similar in the documentation.

Thanks!

Upvotes: 4

Views: 1450

Answers (1)

PV8
PV8

Reputation: 6270

First off all, I would not adjust the tree rules himself, I would adjust the plot.

There is a extra tree ploting package from sklearn . With this adjustment:

precision : int, optional (default=3)

    Number of digits of precision for floating point in the values of impurity, threshold and value attributes of each node.

You can change it, for example:

tree.plot_tree(clf, precision=0)

Should give you rounded numbers.

Upvotes: 1

Related Questions