[python-package] Add tests for more create_tree_digraph() inputs#7166
[python-package] Add tests for more create_tree_digraph() inputs#7166daguirre11 wants to merge 7 commits intolightgbm-org:masterfrom
Conversation
jameslamb
left a comment
There was a problem hiding this comment.
Thanks!
Instead of creating a new fixture and sharing it among multiple tests, could you please just extend the existing test_create_tree_digraph() to be a "deep" test similar to the others in this file?
I don't believe that method modifies the Booster, it should be safe to run multiple calls over the same Booster in the same test.
And we don't use something like pytest-xdist to run tests in parallel, so it's ok to have a lot of testing happening in a single test case.
the random state is fixed making the model fixture deterministic.
I think here's you're referring to the breast_cancer_split fixture? Even with identical input data, there is still non-determinism in LightGBM (see #6731).
Please add the following parameters to the LGBMClassifier() call:
deterministic=Truen_jobs=1force_row_wise=True
Thanks @jameslamb I will make these changes. @jameslamb Yes I was referring to the |
| # test internal_count | ||
| graph = lgb.create_tree_digraph(gbm, tree_index=0, show_info=["internal_count"]) | ||
| graph_body = "".join(graph.body) | ||
| assert "count: 200" in graph_body |
There was a problem hiding this comment.
| assert "count: 200" in graph_body | |
| assert "count: 200" in graph_body, graph_body |
All of the CUDA jobs are failing on this case:
FAILED tests/python_package_test/test_plotting.py::test_create_tree_digraph - assert 'count: 200' in '\tgraph [nodesep=0.05 rankdir=LR ranksep=0.3]\n\tleaf0 [label=<leaf 0: 0.677> color=black fillcolor=white penw... \n \n \n > color=white shape=rectangle]\n'
Let's add this error message to get a bit more logs about what's going on.
There was a problem hiding this comment.
Triggered a run here: https://github.com/lightgbm-org/LightGBM/actions/runs/23394312312
There was a problem hiding this comment.
That failed too. The output was like this:
FAILED tests/python_package_test/test_plotting.py::test_create_tree_digraph - AssertionError: graph [nodesep=0.05 rankdir=LR ranksep=0.3]
leaf0 [label=<leaf 0: <B>0.677</B>> color=black fillcolor=white penwidth=1 shape=ellipse style=""]
split1 -> leaf0 [label=yes color=black penwidth=1]
leaf2 [label=<leaf 2: <B>0.343</B>> color=black fillcolor=white penwidth=1 shape=ellipse style=""]
split1 -> leaf2 [label=no color=black penwidth=1]
split1 [label=<<B>Column_20</B> ≤<B>17.510</B><br/>count: 346> color=black fillcolor="#ffdddd" penwidth=1 shape=rectangle style=filled]
split0 -> split1 [label=yes color=black penwidth=1]
leaf1 [label=<leaf 1: <B>0.286</B>> color=black fillcolor=white penwidth=1 shape=ellipse style=""]
split0 -> leaf1 [label=no color=black penwidth=1]
split0 [label=<<B>Column_27</B> ≤<B>0.146</B><br/>count: 512> color=black fillcolor="#ddffdd" penwidth=1 shape=rectangle style=filled]
legend [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
<TD COLSPAN="2"><B>Monotone constraints</B></TD>
</TR>
<TR>
<TD>Increasing</TD>
<TD BGCOLOR="#ddffdd"></TD>
</TR>
<TR>
<TD>Decreasing</TD>
<TD BGCOLOR="#ffdddd"></TD>
</TR>
</TABLE>
> color=white shape=rectangle]
Co-authored-by: James Lamb <jaylamb20@gmail.com>
Contributes to #7031

BEFORE
AFTER

7 line difference in coverage for
/lightgbm/plotting.pyNOTE
I know these are very specific tests, however, the random state is fixed making the model fixture deterministic. Given other tests depend on the model fixture I expect it to be in a stable state and not change anytime (at least soon)