Skip to content

Commit

Permalink
Restore functionality of max_depth=0 in hist (#7551)
Browse files Browse the repository at this point in the history
* Restore functionality of max_depth=0 in hist

* Add test case
  • Loading branch information
hcho3 committed Jan 10, 2022
1 parent 2db8080 commit 20c0d60
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tree/updater_quantile_hist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void QuantileHistMaker::Builder<GradientSumT>::ExpandTree(
ApplySplit<any_missing>(nodes_for_apply_split, gmat, column_matrix, p_tree);
SplitSiblings(nodes_for_apply_split, &nodes_to_evaluate, p_tree);

if (depth < param_.max_depth) {
if (param_.max_depth == 0 || depth < param_.max_depth) {
size_t i = 0;
for (auto const &gidx : p_fmat->GetBatches<GHistIndexMatrix>(
{GenericParameter::kCpuId, param_.max_bin})) {
Expand Down
15 changes: 15 additions & 0 deletions tests/python/test_tree_regularization.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,18 @@ def test_alpha_and_lambda(self):
# sum_hess = 1.0
# 0.7 = 0.5 - (sum_grad - alpha * sgn(sum_grad)) / (sum_hess + lambda)
assert_approx_equal(preds[0], 0.7)

def test_unlimited_depth(self):
x = np.array([[0], [1], [2], [3]])
y = np.array([0, 1, 2, 3])

model = xgb.XGBRegressor(
n_estimators=1,
eta=1,
tree_method="hist",
grow_policy="lossguide",
reg_lambda=0,
max_leaves=128,
max_depth=0,
).fit(x, y)
assert np.array_equal(model.predict(x), y)

0 comments on commit 20c0d60

Please sign in to comment.