A helper function to extract the matrix of linear coefficients' history from a gblinear model created while using the xgb.cb.gblinear.history callback (which must be added manually as by default it is not used).
xgb.gblinear.history(model, class_index = NULL)For an xgb.train() result, a matrix (either dense or sparse) with the columns
corresponding to iteration's coefficients and the rows corresponding to boosting iterations.
For an xgb.cv() result, a list of such matrices is returned with the elements
corresponding to CV folds.
When there is more than one coefficient per feature (e.g. multi-class classification)
and class_index is not provided,
the result will be reshaped into a vector where coefficients are arranged first by features and
then by class (e.g. first 1 through N coefficients will be for the first class, then
coefficients N+1 through 2N for the second class, and so on).
Either an xgb.Booster or a result of xgb.cv(), trained
using the xgb.cb.gblinear.history callback, but not a booster
loaded from xgb.load() or xgb.load.raw().
zero-based class index to extract the coefficients for only that
specific class in a multinomial multiclass model. When it is NULL, all the
coefficients are returned. Has no effect in non-multiclass models.
Note that this is an R-specific function that relies on R attributes that
are not saved when using XGBoost's own serialization functions like xgb.load()
or xgb.load.raw().
In order for a serialized model to be accepted by this function, one must use R
serializers such as saveRDS().
xgb.cb.gblinear.history, coef.xgb.Booster.