-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
fix of #6580: Exporting a single node DecisionTreeClassifier to dot graph raises error when filled is True #6582
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
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 |
---|---|---|
|
@@ -157,9 +157,12 @@ def get_color(value): | |
else: | ||
# Regression tree or multi-output | ||
color = list(colors['rgb'][0]) | ||
alpha = int(np.round(255 * ((value - colors['bounds'][0]) / | ||
(colors['bounds'][1] - | ||
colors['bounds'][0])), 0)) | ||
if colors['bounds'][0] == colors['bounds'][1]: | ||
alpha = 255 | ||
else: | ||
alpha = int(np.round(255 * ((value - colors['bounds'][0]) / | ||
(colors['bounds'][1] - | ||
colors['bounds'][0])), 0)) | ||
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. niptick: 255 -> 255. |
||
|
||
# Return html color code in #RRGGBBAA format | ||
color.append(alpha) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
X = [[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]] | ||
y = [-1, -1, -1, 1, 1, 1] | ||
y2 = [[-1, 1], [-1, 1], [-1, 1], [1, 2], [1, 2], [1, 3]] | ||
y3 = [0, 0, 0, 0, 0, 0] | ||
w = [1, 1, 1, .5, .5, .5] | ||
|
||
|
||
|
@@ -235,3 +236,19 @@ def test_friedman_mse_in_graphviz(): | |
|
||
for finding in finditer("\[.*?samples.*?\]", dot_data.getvalue()): | ||
assert_in("friedman_mse", finding.group()) | ||
|
||
|
||
def test_graphviz_single_node_tree(): | ||
dtc = DecisionTreeClassifier() | ||
dtc.fit(X, y3) | ||
|
||
out = StringIO() | ||
export_graphviz(dtc, out_file=out, filled=True) | ||
|
||
contents1 = out.getvalue() | ||
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. nitpick: |
||
contents2 = 'digraph Tree {\n' \ | ||
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. Could you avoid
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. nitpick: |
||
'node [shape=box, style="filled", color="black"] ;\n' \ | ||
'0 [label="gini = 0.0\\nsamples = 6\\nvalue = 6.0", fillcolor="#e58139ff"] ;\n' \ | ||
'}' | ||
|
||
assert_equal(contents1, contents2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: Or would it be fun to multiply this by the impurity? (Just wondering out aloud)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(The node's impurity)