Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ jobs:
- {os: macos-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# use 4.0 or 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: 'oldrel-4'}
- {os: windows-latest, r: 'oldrel-1'}

- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
- {os: ubuntu-latest, r: 'oldrel-2'}
- {os: ubuntu-latest, r: 'oldrel-3'}
- {os: ubuntu-latest, r: 'oldrel-4'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ License: MIT + file LICENSE
URL: https://github.com/holub008/xrf
BugReports: https://github.com/holub008/xrf/issues
Depends:
R (>= 4.1.0)
R (>= 4.3.0)
Imports:
cli,
dplyr,
Expand All @@ -26,7 +26,7 @@ Imports:
Matrix,
methods,
rlang,
xgboost (>= 0.71.2)
xgboost (>= 3.1.2.1)
Suggests:
covr,
testthat (>= 3.0.0)
Expand Down
61 changes: 36 additions & 25 deletions R/xrf.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ condition_xgb_control <- function(
data_mutated[[response_var]] <- integer_response - min(integer_response)
}

xgb_control$objective <- get_xgboost_objective(family, call = call)
list(xgb_control = xgb_control, data = data_mutated)
}

Expand All @@ -70,22 +71,6 @@ xrf_preconditions <- function(
)
}

if (!('nrounds' %in% names(xgb_control))) {
cli::cli_abort(
"Must supply an {.arg nrounds} list element to the {.arg xgb_control}
argument.",
call = call
)
}

if ('objective' %in% names(xgb_control)) {
cli::cli_abort(
"User may not supply an {.arg objective} element to the {.arg xgb_control}
argument.",
call = call
)
}

if (!(response_var %in% colnames(data))) {
cli::cli_abort(
"Response variable {.var {response_var}} not present in supplied data",
Expand Down Expand Up @@ -507,6 +492,14 @@ xrf <- function(object, ...) {
#' @importFrom stats terms
#' @importFrom stats update
#'
#' @details
#'
#' In November 2025, the new version of \pkg{xgboost} (3.1.2.1) introduced
#' significant breaking changes. This version of \pkg{xrf} can reproduce
#' predictions from older versions of \pkg{xgboost}. However, there are likely
#' to be differences in \pkg{xrf} model fits between old and new versions of
#' \pkg{xgboost}.
#'
#' @references
#' Friedman, J. H., & Popescu, B. E. (2008). Predictive learning via rule
#' ensembles. \emph{The Annals of Applied Statistics, 2}(3), 916-954.
Expand Down Expand Up @@ -557,12 +550,10 @@ xrf.formula <- function(
xgb_control <- within(xgb_control, rm(nrounds))

if (is.null(prefit_xgb)) {
m_xgb <- xgboost(
data = design_matrix,
label = data[[response_var]],
m_xgb <- xgboost::xgb.train(
xgboost::xgb.DMatrix(design_matrix, label = data[[response_var]]),
nrounds = nrounds,
objective = get_xgboost_objective(family),
params = xgb_control,
params = xgb_params(xgb_control),
verbose = 0
)
rules <- extract_xgb_rules(m_xgb)
Expand Down Expand Up @@ -793,10 +784,13 @@ summary.xrf <- function(object, ...) {
))
cat(paste0('\n\nOriginal Formula:\n\n'))
cat(smaller_formula(object$base_formula))
cat('\n\nTree model:\n\n')
show(summary(object$xgb))
cat('\n\nGLM:\n\n')
show(summary(object$glm))
cli::cli_rule("Tree model")
cat("\n")
print(object$xgb)
Comment thread
holub008 marked this conversation as resolved.
cat("\n")
cli::cli_rule("GLM")
print(object$glm$model)
invisible(object)
}

#' Print an eXtreme RuleFit model
Expand Down Expand Up @@ -828,3 +822,20 @@ smaller_formula <- function(x, ...) {
}
chr_form
}

xgb_params <- function(x, call = rlang::caller_env()) {
cl <- rlang::call2("xgb.params", .ns = "xgboost", !!!x)
res <- try(rlang::eval_tidy(cl, data = x), silent = TRUE)
if (inherits(res, "try-error")) {
msg <- as.character(res)
msg <- strsplit(msg, split = ":")[[1]][-(1:3)]
msg <- gsub("\\n", "", msg)
msg <- trimws(msg)
msg <- paste0(msg, collapse = "")
cli::cli_abort(
"There was an error when parsing the xgboost arguments: {msg}",
call = call
)
}
res
}
13 changes: 13 additions & 0 deletions inst/xgb_1_7_11.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# pak::pak(c("xrf", "xgboost"), ask = FALSE)
library(xrf)
library(xgboost)
# xgboost_1.7.11.1 xrf_0.2.2

set.seed(832)
xgb_1_7_11_fit <- xrf(mpg ~ ., data = mtcars[1:28, ], family = "gaussian")
xgb_1_7_11_pred <- predict(xgb_1_7_11_fit, mtcars[29:32, ])
save(xgb_1_7_11_fit, xgb_1_7_11_pred, file = "inst/xgb_1_7_11.RData")

if (!interactive()) {
q("no")
}
Binary file added inst/xgb_1_7_11.RData
Binary file not shown.
7 changes: 7 additions & 0 deletions man/xrf.formula.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/testthat/test_xgb_1_7_11.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# In November 2025, the new version of xgboost has api changes
# that are breaking changes. See https://github.com/dmlc/xgboost/issues/11430
# This file uses the current CRAN versions to ensure that prediction
# works in updated versions of xrf and xgboost.

test_that('prediction works on xgboost versions < 3.0', {
Comment thread
holub008 marked this conversation as resolved.
load(system.file("xgb_1_7_11.RData", package = "xrf"), verbose = FALSE)
xgb_3_1_2_1_pred <- predict(xgb_1_7_11_fit, mtcars[29:32, ])

expect_equal(xgb_1_7_11_pred, xgb_3_1_2_1_pred)
})