Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX accept array-like in feature_names for plot_tree - #27292

Merged
jeremiedbb merged 6 commits into
scikit-learn:mainfrom
rprkh:fix_plot_tree
Sep 6, 2023
Merged

FIX accept array-like in feature_names for plot_tree#27292
jeremiedbb merged 6 commits into
scikit-learn:mainfrom
rprkh:fix_plot_tree

Conversation

@rprkh

@rprkh rprkh commented Sep 4, 2023

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Sep 4, 2023

Copy link
Copy Markdown

✔️ Linting Passed

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

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

Comment thread sklearn/tree/_export.py Outdated
@betatim

betatim commented Sep 5, 2023

Copy link
Copy Markdown
Member

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?

@betatim betatim left a comment

Copy link
Copy Markdown
Member

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

jeremiedbb commented Sep 5, 2023

Copy link
Copy Markdown
Member

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

rprkh commented Sep 5, 2023

Copy link
Copy Markdown
Contributor Author

Added the changes

@jeremiedbb jeremiedbb left a comment

Copy link
Copy Markdown
Member

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
jeremiedbb added a commit that referenced this pull request Sep 20, 2023
Co-authored-by: Jérémie du Boisberranger <[email protected]>
REDVM pushed a commit to REDVM/scikit-learn that referenced this pull request Nov 16, 2023
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