8000 FIX accept `array-like` in `feature_names` for `plot_tree` by rprkh · Pull Request #27292 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@rprkh
Copy link
Contributor
@rprkh rprkh commented Sep 4, 2023

Reference Issues/PRs

Partially fixes #27271

What does this implement/fix? Explain your changes.

The feature_names parameter now accepts an array.

Any other comments?

from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import plot_tree
import matplotlib.pyplot as plt


cancer = load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(cancer.data, cancer.target)
tree = DecisionTreeClassifier(max_depth=1).fit(X_train, y_train)

plot_tree(tree, class_names=cancer.target_names,
          feature_names=cancer.feature_names)
plt.show()

The code above will execute without any errors

@github-actions
Copy link
github-actions bot commented Sep 4, 2023

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 7603506. Link to the linter CI: here

@betatim
Copy link
Member
betatim commented Sep 5, 2023

I don't know what we usually do in terms of adding a no-regression test for parameter validation bugs. Maybe we don't need one. What do others think?

Copy link
Member
@betatim betatim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After removing list this looks good to me.

@jeremiedbb
Copy link
Member
jeremiedbb commented Sep 5, 2023

Thanks for the PR @rprkh. The docstring also needs to be updated. Please also add a entry in the what's new (1.3.1)

@rprkh
Copy link
Contributor Author
rprkh commented Sep 5, 2023

Added the changes

Copy link
Member
@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @rprkh

@jeremiedbb jeremiedbb enabled auto-merge (squash) September 6, 2023 10:19
@jeremiedbb jeremiedbb merged commit e24c13c into scikit-learn:main Sep 6, 2023
@rprkh rprkh deleted the fix_plot_tree branch September 6, 2023 15:20
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Sep 18, 2023
…arn#27292)

Co-authored-by: Jérémie du Boisberranger <34657725+jeremiedbb@users.noreply.github.com>
jeremiedbb added a commit that referenced this pull request Sep 20, 2023
Co-authored-by: Jérémie du Boisberranger <34657725+jeremiedbb@users.noreply.github.com>
REDVM pushed a commit to REDVM/scikit-learn that referenced this pull request Nov 16, 2023
…arn#27292)

Co-authored-by: Jérémie du Boisberranger <34657725+jeremiedbb@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature_names returned by load_breast_cancer() is np.array, not list.

3 participants

0