-
-
Notifications
You must be signed in to change notification settings - Fork 26k
ENH Adds class_names
to tree.export_text
#25387
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
Changes from all commits
6a88e33
ae72848
ae2d3e9
d299d45
fd30a47
38b15ff
013fc0e
39cf9e2
11c32ef
d9066ab
a720c93
deb0248
1803d3c
acc505d
7f14483
307ad81
7e01150
8626844
d248eac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -923,6 +923,7 @@ def export_text( | |
decision_tree, | ||
*, | ||
feature_names=None, | ||
class_names=None, | ||
max_depth=10, | ||
spacing=3, | ||
decimals=2, | ||
|
@@ -943,6 +944,17 @@ def export_text( | |
A list of length n_features containing the feature names. | ||
If None generic names will be used ("feature_0", "feature_1", ...). | ||
|
||
class_names : list or None, default=None | ||
Names of each of the target classes in ascending numerical order. | ||
Only relevant for classification and not supported for multi-output. | ||
glemaitre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- if `None`, the class names are delegated to `decision_tree.classes_`; | ||
- if a list, then `class_names` will be used as class names instead | ||
of `decision_tree.classes_`. The length of `class_names` must match | ||
the length of `decision_tree.classes_`. | ||
|
||
.. versionadded:: 1.3 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs a |
||
max_depth : int, default=10 | ||
Only the first max_depth levels of the tree are exported. | ||
Truncated branches will be marked with "...". | ||
|
@@ -986,7 +998,15 @@ def export_text( | |
check_is_fitted(decision_tree) | ||
tree_ = decision_tree.tree_ | ||
if is_classifier(decision_tree): | ||
class_names = decision_tree.classes_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uhm it seems that I misunderstood something when reading the documentation at first. We already uses Sorry to have brought this way. We will need to modify (remove) the code :) |
||
if class_names is None: | ||
class_names = decision_tree.classes_ | ||
elif len(class_names) != len(decision_tree.classes_): | ||
raise ValueError( | ||
"When `class_names` is a list, it should contain as" | ||
" many items as `decision_tree.classes_`. Got" | ||
f" {len(class_names)} while the tree was fitted with" | ||
f" {len(decision_tree.classes_)} classes." | ||
) | ||
right_child_fmt = "{} {} <= {}\n" | ||
left_child_fmt = "{} {} > {}\n" | ||
truncation_fmt = "{} {}\n" | ||
|
Uh oh!
There was an error while loading. Please reload this page.