(self)
| 33 | return res |
| 34 | |
| 35 | def test_trees_to_dataframe(self): |
| 36 | bst = self.build_model(max_depth=5, num_round=10) |
| 37 | gain_from_dump = self.parse_dumped_model( |
| 38 | booster=bst, item_to_get="gain", splitter="," |
| 39 | ) |
| 40 | cover_from_dump = self.parse_dumped_model( |
| 41 | booster=bst, item_to_get="cover", splitter="\n" |
| 42 | ) |
| 43 | # method being tested |
| 44 | df = bst.trees_to_dataframe() |
| 45 | |
| 46 | # test for equality of gains |
| 47 | gain_from_df = df[df.Feature != "Leaf"][["Gain"]].sum() |
| 48 | assert np.allclose(gain_from_dump, gain_from_df) |
| 49 | |
| 50 | # test for equality of covers |
| 51 | cover_from_df = df.Cover.sum() |
| 52 | assert np.allclose(cover_from_dump, cover_from_df) |
| 53 | |
| 54 | def test_tree_to_df_categorical(self) -> None: |
| 55 | run_tree_to_df_categorical("approx", "cpu") |
nothing calls this directly
no test coverage detected