Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decision Tree visualize wrong path #294

Open
wim50594 opened this issue May 31, 2023 · 1 comment
Open

Decision Tree visualize wrong path #294

wim50594 opened this issue May 31, 2023 · 1 comment

Comments

@wim50594
Copy link

Description
If the path of a DecisionTree is to be visualized for a single instance and the feature value is exactly the split value, the right path is selected. However, with Sklearn, the decision goes left for less than or equal to. In the end, an incorrect classification is displayed due to the wrong path.

To Reproduce

import dtreeviz
import numpy as np
import sklearn.tree
from sklearn.tree import DecisionTreeClassifier

X = np.expand_dims(np.arange(10), axis=1)
y = np.asarray(5*[False] + 5*[True])

clf = DecisionTreeClassifier().fit(X, y)
sklearn.tree.plot_tree(clf, class_names=["False", "True"])

sktree

viz_model = dtreeviz.model(clf, X_train=X, y_train=y, class_names=["False", "True"], feature_names='x1')
viz_model.view()

dtree

x = np.asarray([4.5])
clf.predict([x])
# outputs array([False])
x = np.asarray([4.5])
viz_model.view(x=x)

path

Expected behavior
The left path should be chosen and thus the classification result "False" should also be displayed. In other words: If the split value is less than or equal to the split value, the left path should be selected.

Environment
Used scikit-learn version 1.2.2 (lates)

@tlapusan
Copy link
Collaborator

tlapusan commented Jun 1, 2023

Thanks @wim50594, it helps that you created the steps to reproduce the issue. I will take a look soon, right now I'm in vacation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants