Skip to content

Commit 15b7257

Browse files
authored
[R] update serialization advise for new xgboost class (dmlc#10794)
1 parent 4f88ada commit 15b7257

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

R-package/R/utils.R

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ NULL
427427
#' its own serializers with better compatibility guarantees, which allow loading
428428
#' said models in other language bindings of XGBoost.
429429
#'
430-
#' Note that an `xgb.Booster` object, outside of its core components, might also keep:
430+
#' Note that an `xgb.Booster` object (**as produced by [xgb.train()]**, see rest of the doc
431+
#' for objects produced by [xgboost()]), outside of its core components, might also keep:
431432
#' - Additional model configuration (accessible through [xgb.config()]), which includes
432433
#' model fitting parameters like `max_depth` and runtime parameters like `nthread`.
433434
#' These are not necessarily useful for prediction/importance/plotting.
@@ -450,6 +451,16 @@ NULL
450451
#' not used for prediction / importance / plotting / etc.
451452
#' These R attributes are only preserved when using R's serializers.
452453
#'
454+
#' In addition to the regular `xgb.Booster` objects producted by [xgb.train()], the
455+
#' function [xgboost()] produces a different subclass `xgboost`, which keeps other
456+
#' additional metadata as R attributes such as class names in classification problems,
457+
#' and which has a dedicated `predict` method that uses different defaults. XGBoost's
458+
#' own serializers can work with this `xgboost` class, but as they do not keep R
459+
#' attributes, the resulting object, when deserialized, is downcasted to the regular
460+
#' `xgb.Booster` class (i.e. it loses the metadata, and the resulting object will use
461+
#' `predict.xgb.Booster` instead of `predict.xgboost`) - for these `xgboost` objects,
462+
#' `saveRDS` might thus be a better option if the extra functionalities are needed.
463+
#'
453464
#' Note that XGBoost models in R starting from version `2.1.0` and onwards, and
454465
#' XGBoost models before version `2.1.0`; have a very different R object structure and
455466
#' are incompatible with each other. Hence, models that were saved with R serializers
@@ -474,9 +485,9 @@ NULL
474485
#' as part of another R object.
475486
#'
476487
#' Use [saveRDS()] if you require the R-specific attributes that a booster might have, such
477-
#' as evaluation logs, but note that future compatibility of such objects is outside XGBoost's
478-
#' control as it relies on R's serialization format (see e.g. the details section in
479-
#' [serialize] and [save()] from base R).
488+
#' as evaluation logs or the model class `xgboost` instead of `xgb.Booster`, but note that
489+
#' future compatibility of such objects is outside XGBoost's control as it relies on R's
490+
#' serialization format (see e.g. the details section in [serialize] and [save()] from base R).
480491
#'
481492
#' For more details and explanation about model persistence and archival, consult the page
482493
#' \url{https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html}.

R-package/man/a-compatibility-note-for-saveRDS-save.Rd

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)