Update GradientBoost to xgboost >= 2.0 API (xgb.DMatrix)#48
Draft
instantepiphany wants to merge 1 commit into
Draft
Update GradientBoost to xgboost >= 2.0 API (xgb.DMatrix)#48instantepiphany wants to merge 1 commit into
instantepiphany wants to merge 1 commit into
Conversation
xgboost >= 2.0 enforces inherits(data, "xgb.DMatrix") inside xgb.cv() and xgb.train(), so passing a raw matrix now fails with `inherits(data, "xgb.DMatrix") is not TRUE`. The `label` arg has also been removed from xgb.cv(), and xgboost()'s legacy signature was renamed (data -> x, label -> y). Build an xgb.DMatrix once from numeric.data$X/y, pass it to xgb.cv, switch the fit calls to xgb.train so the existing $original (xgb.Booster) contract is preserved, and read best_iteration from $early_stop where the new xgb.cv now exposes it. Bump xgboost requirement to (>= 2.0.0). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GradientBoost()was written against the pre-2.0 xgboost API (raw matrix +label =arg). Since xgboost 2.0,xgb.cv()andxgb.train()enforceinherits(data, \"xgb.DMatrix\"), andxgb.cv()no longer acceptslabel. The legacyxgboost()wrapper also renameddata→xandlabel→y. As of the version currently shipping in NixR (xgboost 3.2.0.1), every Gradient Boosting test in the regression suite fails before the first round of training with:```
Error: inherits(data, "xgb.DMatrix") is not TRUE
```
(The error is emitted by `stopifnot()` at xgboost `R/xgb.cv.R:118`, which quotes the unevaluated expression — i.e. the variable is named `data`, not `dada`.)
Surfaced by the Standard R Tests / Machine Learning - Gradient Boosting.Q regression run #7389: log.htm. The Q file's `tree` RItem (and all sibling `xgb*`, `importance tree`, `gradient.boost`, `imputation`, `tree with grid` items) all funnel through `GradientBoost()`, so they all fail the same way.
Changes
Reproduction
Reproduce the original failure (raw matrix into modern xgb.cv):
```bash
cd /path/to/r-server
nix run .#R -- --vanilla -e 'set.seed(1)
x <- matrix(rnorm(40), 20, 2)
y <- sample(0:1, 20, replace = TRUE)
xgboost::xgb.cv(data = x, label = y, nrounds = 2, nfold = 3,
params = list(objective = "binary:logistic"), verbose = 0)'
-> Error: inherits(data, "xgb.DMatrix") is not TRUE
-> Warning: Parameter(s) have been removed from this function: label.
```
Confirm the new code path works against the same xgboost:
```bash
nix run .#R -- --vanilla -e 'library(xgboost)
set.seed(1)
x <- matrix(rnorm(60), 30, 2)
y <- sample(0:1, 30, replace = TRUE)
dtrain <- xgb.DMatrix(data = x, label = y)
xgb.cv(data = dtrain, nrounds = 5, nfold = 3,
params = list(objective = "binary:logistic", num_class = 1, max_depth = 3),
verbose = 0)
xgb.train(data = dtrain,
params = list(objective = "binary:logistic", num_class = 1, max_depth = 3),
nrounds = 3, verbose = 0)'
-> xgb.cv ok; xgb.train returns class "xgb.Booster"
```
Build this branch as an installable R package via the NixR adhoc-deployment branch (override the flipMultivariates input to point at your local checkout of this branch):
```bash
nix build 'git+ssh://git@github.com/displayr/NixR?ref=untracked-update-nixpkgs#pkgs.x86_64-linux.rPackages.flipMultivariates' \
--override-input flipMultivariates .
```
Test plan
🤖 Generated with Claude Code