MCPcopy Create free account
hub / github.com/dmlc/xgboost / test_trees_to_dataframe

Method test_trees_to_dataframe

tests/python/test_parse_tree.py:35–52  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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")

Callers

nothing calls this directly

Calls 3

build_modelMethod · 0.95
parse_dumped_modelMethod · 0.95
trees_to_dataframeMethod · 0.80

Tested by

no test coverage detected