% Generated by roxygen2: do not edit by hand % Please edit documentation in R/xgb.Booster.R \name{xgb.attr} \alias{xgb.attr} \alias{xgb.attr<-} \alias{xgb.attributes} \alias{xgb.attributes<-} \title{Accessors for serializable attributes of a model} \usage{ xgb.attr(object, name) xgb.attr(object, name) <- value xgb.attributes(object) xgb.attributes(object) <- value } \arguments{ \item{object}{Object of class \code{xgb.Booster}. \strong{Will be modified in-place} when assigning to it.} \item{name}{A non-empty character string specifying which attribute is to be accessed.} \item{value}{For \verb{xgb.attr<-}, a value of an attribute; for \verb{xgb.attributes<-}, it is a list (or an object coercible to a list) with the names of attributes to set and the elements corresponding to attribute values. Non-character values are converted to character. When an attribute value is not a scalar, only the first index is used. Use \code{NULL} to remove an attribute.} } \value{ \itemize{ \item \code{xgb.attr()} returns either a string value of an attribute or \code{NULL} if an attribute wasn't stored in a model. \item \code{xgb.attributes()} returns a list of all attributes stored in a model or \code{NULL} if a model has no stored attributes. } } \description{ These methods allow to manipulate the key-value attribute strings of an XGBoost model. } \details{ The primary purpose of XGBoost model attributes is to store some meta data about the model. Note that they are a separate concept from the object attributes in R. Specifically, they refer to key-value strings that can be attached to an XGBoost model, stored together with the model's binary representation, and accessed later (from R or any other interface). In contrast, any R attribute assigned to an R object of \code{xgb.Booster} class would not be saved by \code{\link[=xgb.save]{xgb.save()}} because an XGBoost model is an external memory object and its serialization is handled externally. Also, setting an attribute that has the same name as one of XGBoost's parameters wouldn't change the value of that parameter for a model. Use \code{\link[=xgb.parameters<-]{xgb.parameters<-()}} to set or change model parameters. The \code{\link[=xgb.attributes<-]{xgb.attributes<-()}} setter either updates the existing or adds one or several attributes, but it doesn't delete the other existing attributes. Important: since this modifies the booster's C object, semantics for assignment here will differ from R's, as any object reference to the same booster will be modified too, while assignment of R attributes through \verb{attributes(model)$ <- } will follow the usual copy-on-write R semantics (see \code{\link[=xgb.copy.Booster]{xgb.copy.Booster()}} for an example of these behaviors). } \examples{ data(agaricus.train, package = "xgboost") train <- agaricus.train bst <- xgb.train( data = xgb.DMatrix(train$data, label = train$label), max_depth = 2, eta = 1, nthread = 2, nrounds = 2, objective = "binary:logistic" ) xgb.attr(bst, "my_attribute") <- "my attribute value" print(xgb.attr(bst, "my_attribute")) xgb.attributes(bst) <- list(a = 123, b = "abc") fname <- file.path(tempdir(), "xgb.ubj") xgb.save(bst, fname) bst1 <- xgb.load(fname) print(xgb.attr(bst1, "my_attribute")) print(xgb.attributes(bst1)) # deletion: xgb.attr(bst1, "my_attribute") <- NULL print(xgb.attributes(bst1)) xgb.attributes(bst1) <- list(a = NULL, b = NULL) print(xgb.attributes(bst1)) }