Get one attribute of a lgb.Dataset

get_field(dataset, field_name)

# S3 method for lgb.Dataset
get_field(dataset, field_name)



Object of class lgb.Dataset


String with the name of the attribute to get. One of the following.

  • label: label lightgbm learns from ;

  • weight: to do a weight rescale ;

  • group: used for learning-to-rank tasks. An integer vector describing how to group rows together as ordered results from the same set of candidate results to be ranked. For example, if you have a 100-document dataset with group = c(10, 20, 40, 10, 10, 10), that means that you have 6 groups, where the first 10 records are in the first group, records 11-30 are in the second group, etc.

  • init_score: initial score is the base prediction lightgbm will boost from.


requested attribute


# \donttest{
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)

labels <- lightgbm::get_field(dtrain, "label")
lightgbm::set_field(dtrain, "label", 1 - labels)

labels2 <- lightgbm::get_field(dtrain, "label")
stopifnot(all(labels2 == 1 - labels))
# }