Migrating code from previous XGBoost versions
XGBoost’s R language bindings had large breaking changes between versions 1.x and 2.x. R code that was working with past XGBoost versions might require modifications to work with the newer versions. This guide outlines the main differences:
- Function
xgboost(): Previously, this function accepted arguments ‘data’ and ‘label’, which have now been renamed to ‘x’ and ‘y’, in line with other popular R packages.
Previously, the ‘data’ argument which is now ‘x’ had to be passed as either an XGBoost ‘DMatrix’ or as an R matrix. Now the argument allows R data.frames, matrices, and sparse matrices from the ‘Matrix’ package, but not XGBoost’s own DMatrices. Categorical columns will be deduced from the types of the columns when passing a data.frame.
Previously, the ‘label’ data which is now ‘y’ had to be passed to
xgboost()encoded in the format used by the XGBoost core library - meaning: binary variables had to be encoded to 0/1, bounds for survival objectives had to be passed as different arguments, among others. In the newest versions, ‘y’ now doesn’t need to be manually encoded beforehand: it should be passed as an R object of the corresponding class as regression functions from base R and core R packages for the corresponding XGBoost objective - e.g. classification problems should be passed afactor, survival problems a, regression problems a numeric vector, and so on. Learning-to-rank is not supported by , but is supported by .
- Function