Cover approx tree method for categorical data tests. (#7569)
* Add tree to df tests. * Add plotting tests. * Add histogram tests.
This commit is contained in:
@@ -12,7 +12,6 @@ rng = np.random.RandomState(1994)
|
||||
|
||||
|
||||
class TestTreesToDataFrame:
|
||||
|
||||
def build_model(self, max_depth, num_round):
|
||||
dtrain = xgb.DMatrix(dpath + 'agaricus.txt.train')
|
||||
param = {'max_depth': max_depth, 'objective': 'binary:logistic',
|
||||
@@ -48,3 +47,26 @@ class TestTreesToDataFrame:
|
||||
# test for equality of covers
|
||||
cover_from_df = df.Cover.sum()
|
||||
assert np.allclose(cover_from_dump, cover_from_df)
|
||||
|
||||
def run_tree_to_df_categorical(self, tree_method: str) -> None:
|
||||
X, y = tm.make_categorical(100, 10, 31, False)
|
||||
Xy = xgb.DMatrix(X, y, enable_categorical=True)
|
||||
booster = xgb.train({"tree_method": tree_method}, Xy, num_boost_round=10)
|
||||
df = booster.trees_to_dataframe()
|
||||
for _, x in df.iterrows():
|
||||
if x["Feature"] != "Leaf":
|
||||
assert len(x["Category"]) >= 1
|
||||
|
||||
def test_tree_to_df_categorical(self) -> None:
|
||||
self.run_tree_to_df_categorical("approx")
|
||||
|
||||
def run_split_value_histograms(self, tree_method) -> None:
|
||||
X, y = tm.make_categorical(1000, 10, 13, False)
|
||||
reg = xgb.XGBRegressor(tree_method=tree_method, enable_categorical=True)
|
||||
reg.fit(X, y)
|
||||
|
||||
with pytest.raises(ValueError, match="doesn't"):
|
||||
reg.get_booster().get_split_value_histogram("3", bins=5)
|
||||
|
||||
def test_split_value_histograms(self):
|
||||
self.run_split_value_histograms("approx")
|
||||
|
||||
Reference in New Issue
Block a user