@@ -49,6 +49,7 @@ condition_xgb_control <- function(
4949 data_mutated [[response_var ]] <- integer_response - min(integer_response )
5050 }
5151
52+ xgb_control $ objective <- get_xgboost_objective(family , call = call )
5253 list (xgb_control = xgb_control , data = data_mutated )
5354}
5455
@@ -70,22 +71,6 @@ xrf_preconditions <- function(
7071 )
7172 }
7273
73- if (! (' nrounds' %in% names(xgb_control ))) {
74- cli :: cli_abort(
75- " Must supply an {.arg nrounds} list element to the {.arg xgb_control}
76- argument." ,
77- call = call
78- )
79- }
80-
81- if (' objective' %in% names(xgb_control )) {
82- cli :: cli_abort(
83- " User may not supply an {.arg objective} element to the {.arg xgb_control}
84- argument." ,
85- call = call
86- )
87- }
88-
8974 if (! (response_var %in% colnames(data ))) {
9075 cli :: cli_abort(
9176 " Response variable {.var {response_var}} not present in supplied data" ,
@@ -507,6 +492,14 @@ xrf <- function(object, ...) {
507492# ' @importFrom stats terms
508493# ' @importFrom stats update
509494# '
495+ # ' @details
496+ # '
497+ # ' In November 2025, the new version of \pkg{xgboost} (3.1.2.1) introduced
498+ # ' significant breaking changes. This version of \pkg{xrf} can reproduce
499+ # ' predictions from older versions of \pkg{xgboost}. However, there are likely
500+ # ' to be differences in \pkg{xrf} model fits between old and new versions of
501+ # ' \pkg{xgboost}.
502+ # '
510503# ' @references
511504# ' Friedman, J. H., & Popescu, B. E. (2008). Predictive learning via rule
512505# ' ensembles. \emph{The Annals of Applied Statistics, 2}(3), 916-954.
@@ -557,12 +550,10 @@ xrf.formula <- function(
557550 xgb_control <- within(xgb_control , rm(nrounds ))
558551
559552 if (is.null(prefit_xgb )) {
560- m_xgb <- xgboost(
561- data = design_matrix ,
562- label = data [[response_var ]],
553+ m_xgb <- xgboost :: xgb.train(
554+ xgboost :: xgb.DMatrix(design_matrix , label = data [[response_var ]]),
563555 nrounds = nrounds ,
564- objective = get_xgboost_objective(family ),
565- params = xgb_control ,
556+ params = xgb_params(xgb_control ),
566557 verbose = 0
567558 )
568559 rules <- extract_xgb_rules(m_xgb )
@@ -793,10 +784,13 @@ summary.xrf <- function(object, ...) {
793784 ))
794785 cat(paste0(' \n\n Original Formula:\n\n ' ))
795786 cat(smaller_formula(object $ base_formula ))
796- cat(' \n\n Tree model:\n\n ' )
797- show(summary(object $ xgb ))
798- cat(' \n\n GLM:\n\n ' )
799- show(summary(object $ glm ))
787+ cli :: cli_rule(" Tree model" )
788+ cat(" \n " )
789+ print(object $ xgb )
790+ cat(" \n " )
791+ cli :: cli_rule(" GLM" )
792+ print(object $ glm $ model )
793+ invisible (object )
800794}
801795
802796# ' Print an eXtreme RuleFit model
@@ -828,3 +822,20 @@ smaller_formula <- function(x, ...) {
828822 }
829823 chr_form
830824}
825+
826+ xgb_params <- function (x , call = rlang :: caller_env()) {
827+ cl <- rlang :: call2(" xgb.params" , .ns = " xgboost" , !!! x )
828+ res <- try(rlang :: eval_tidy(cl , data = x ), silent = TRUE )
829+ if (inherits(res , " try-error" )) {
830+ msg <- as.character(res )
831+ msg <- strsplit(msg , split = " :" )[[1 ]][- (1 : 3 )]
832+ msg <- gsub(" \\ n" , " " , msg )
833+ msg <- trimws(msg )
834+ msg <- paste0(msg , collapse = " " )
835+ cli :: cli_abort(
836+ " There was an error when parsing the xgboost arguments: {msg}" ,
837+ call = call
838+ )
839+ }
840+ res
841+ }
0 commit comments