Skip to content

Commit

Permalink
Test.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Apr 29, 2022
1 parent 1f40cbf commit 4e82d5a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/python-gpu/test_gpu_updaters.py
Expand Up @@ -61,6 +61,9 @@ def test_gpu_hist(self, param, num_rounds, dataset):
def test_categorical(self, rows, cols, rounds, cats):
self.cputest.run_categorical_basic(rows, cols, rounds, cats, "gpu_hist")

def test_max_cat(self) -> None:
self.cputest.run_max_cat("gpu_hist")

def test_categorical_32_cat(self):
'''32 hits the bound of integer bitset, so special test'''
rows = 1000
Expand Down
26 changes: 26 additions & 0 deletions tests/python/test_updaters.py
@@ -1,3 +1,5 @@
from random import choice
from string import ascii_lowercase
import testing as tm
import pytest
import xgboost as xgb
Expand Down Expand Up @@ -169,6 +171,30 @@ def run_invalid_category(self, tree_method: str) -> None:

def test_invalid_category(self) -> None:
self.run_invalid_category("approx")
self.run_invalid_category("hist")

def run_max_cat(self, tree_method: str) -> None:
"""Test data with size smaller than number of categories."""
import pandas as pd
n_cat = 100
n = 5
X = pd.Series(
["".join(choice(ascii_lowercase) for i in range(3)) for i in range(n_cat)],
dtype="category",
)[:n].to_frame()

reg = xgb.XGBRegressor(
enable_categorical=True,
tree_method=tree_method,
n_estimators=10,
)
y = pd.Series(range(n))
reg.fit(X=X, y=y, eval_set=[(X, y)])
assert tm.non_increasing(reg.evals_result()["validation_0"]["rmse"])

@pytest.mark.parametrize("tree_method", ["hist", "approx"])
def test_max_cat(self, tree_method) -> None:
self.run_max_cat(tree_method)

def run_categorical_basic(self, rows, cols, rounds, cats, tree_method):
onehot, label = tm.make_categorical(rows, cols, cats, True)
Expand Down

0 comments on commit 4e82d5a

Please sign in to comment.