Only column names are supported for lgb.Dataset, thus setting of row names would have no effect and returned row names would be NULL.

# S3 method for lgb.Dataset
dimnames(x)

# S3 method for lgb.Dataset
dimnames(x) <- value

Arguments

x

object of class lgb.Dataset

value

a list of two elements: the first one is ignored and the second one is column names

Details

Generic dimnames methods are used by colnames. Since row names are irrelevant, it is recommended to use colnames directly.

Examples

library(lightgbm) data(agaricus.train, package = "lightgbm") train <- agaricus.train dtrain <- lgb.Dataset(train$data, label = train$label) lgb.Dataset.construct(dtrain) dimnames(dtrain)
#> [[1]] #> NULL #> #> [[2]] #> [1] "cap-shape=bell" "cap-shape=conical" #> [3] "cap-shape=convex" "cap-shape=flat" #> [5] "cap-shape=knobbed" "cap-shape=sunken" #> [7] "cap-surface=fibrous" "cap-surface=grooves" #> [9] "cap-surface=scaly" "cap-surface=smooth" #> [11] "cap-color=brown" "cap-color=buff" #> [13] "cap-color=cinnamon" "cap-color=gray" #> [15] "cap-color=green" "cap-color=pink" #> [17] "cap-color=purple" "cap-color=red" #> [19] "cap-color=white" "cap-color=yellow" #> [21] "bruises?=bruises" "bruises?=no" #> [23] "odor=almond" "odor=anise" #> [25] "odor=creosote" "odor=fishy" #> [27] "odor=foul" "odor=musty" #> [29] "odor=none" "odor=pungent" #> [31] "odor=spicy" "gill-attachment=attached" #> [33] "gill-attachment=descending" "gill-attachment=free" #> [35] "gill-attachment=notched" "gill-spacing=close" #> [37] "gill-spacing=crowded" "gill-spacing=distant" #> [39] "gill-size=broad" "gill-size=narrow" #> [41] "gill-color=black" "gill-color=brown" #> [43] "gill-color=buff" "gill-color=chocolate" #> [45] "gill-color=gray" "gill-color=green" #> [47] "gill-color=orange" "gill-color=pink" #> [49] "gill-color=purple" "gill-color=red" #> [51] "gill-color=white" "gill-color=yellow" #> [53] "stalk-shape=enlarging" "stalk-shape=tapering" #> [55] "stalk-root=bulbous" "stalk-root=club" #> [57] "stalk-root=cup" "stalk-root=equal" #> [59] "stalk-root=rhizomorphs" "stalk-root=rooted" #> [61] "stalk-root=missing" "stalk-surface-above-ring=fibrous" #> [63] "stalk-surface-above-ring=scaly" "stalk-surface-above-ring=silky" #> [65] "stalk-surface-above-ring=smooth" "stalk-surface-below-ring=fibrous" #> [67] "stalk-surface-below-ring=scaly" "stalk-surface-below-ring=silky" #> [69] "stalk-surface-below-ring=smooth" "stalk-color-above-ring=brown" #> [71] "stalk-color-above-ring=buff" "stalk-color-above-ring=cinnamon" #> [73] "stalk-color-above-ring=gray" "stalk-color-above-ring=orange" #> [75] "stalk-color-above-ring=pink" "stalk-color-above-ring=red" #> [77] "stalk-color-above-ring=white" "stalk-color-above-ring=yellow" #> [79] "stalk-color-below-ring=brown" "stalk-color-below-ring=buff" #> [81] "stalk-color-below-ring=cinnamon" "stalk-color-below-ring=gray" #> [83] "stalk-color-below-ring=orange" "stalk-color-below-ring=pink" #> [85] "stalk-color-below-ring=red" "stalk-color-below-ring=white" #> [87] "stalk-color-below-ring=yellow" "veil-type=partial" #> [89] "veil-type=universal" "veil-color=brown" #> [91] "veil-color=orange" "veil-color=white" #> [93] "veil-color=yellow" "ring-number=none" #> [95] "ring-number=one" "ring-number=two" #> [97] "ring-type=cobwebby" "ring-type=evanescent" #> [99] "ring-type=flaring" "ring-type=large" #> [101] "ring-type=none" "ring-type=pendant" #> [103] "ring-type=sheathing" "ring-type=zone" #> [105] "spore-print-color=black" "spore-print-color=brown" #> [107] "spore-print-color=buff" "spore-print-color=chocolate" #> [109] "spore-print-color=green" "spore-print-color=orange" #> [111] "spore-print-color=purple" "spore-print-color=white" #> [113] "spore-print-color=yellow" "population=abundant" #> [115] "population=clustered" "population=numerous" #> [117] "population=scattered" "population=several" #> [119] "population=solitary" "habitat=grasses" #> [121] "habitat=leaves" "habitat=meadows" #> [123] "habitat=paths" "habitat=urban" #> [125] "habitat=waste" "habitat=woods" #>
colnames(dtrain)
#> [1] "cap-shape=bell" "cap-shape=conical" #> [3] "cap-shape=convex" "cap-shape=flat" #> [5] "cap-shape=knobbed" "cap-shape=sunken" #> [7] "cap-surface=fibrous" "cap-surface=grooves" #> [9] "cap-surface=scaly" "cap-surface=smooth" #> [11] "cap-color=brown" "cap-color=buff" #> [13] "cap-color=cinnamon" "cap-color=gray" #> [15] "cap-color=green" "cap-color=pink" #> [17] "cap-color=purple" "cap-color=red" #> [19] "cap-color=white" "cap-color=yellow" #> [21] "bruises?=bruises" "bruises?=no" #> [23] "odor=almond" "odor=anise" #> [25] "odor=creosote" "odor=fishy" #> [27] "odor=foul" "odor=musty" #> [29] "odor=none" "odor=pungent" #> [31] "odor=spicy" "gill-attachment=attached" #> [33] "gill-attachment=descending" "gill-attachment=free" #> [35] "gill-attachment=notched" "gill-spacing=close" #> [37] "gill-spacing=crowded" "gill-spacing=distant" #> [39] "gill-size=broad" "gill-size=narrow" #> [41] "gill-color=black" "gill-color=brown" #> [43] "gill-color=buff" "gill-color=chocolate" #> [45] "gill-color=gray" "gill-color=green" #> [47] "gill-color=orange" "gill-color=pink" #> [49] "gill-color=purple" "gill-color=red" #> [51] "gill-color=white" "gill-color=yellow" #> [53] "stalk-shape=enlarging" "stalk-shape=tapering" #> [55] "stalk-root=bulbous" "stalk-root=club" #> [57] "stalk-root=cup" "stalk-root=equal" #> [59] "stalk-root=rhizomorphs" "stalk-root=rooted" #> [61] "stalk-root=missing" "stalk-surface-above-ring=fibrous" #> [63] "stalk-surface-above-ring=scaly" "stalk-surface-above-ring=silky" #> [65] "stalk-surface-above-ring=smooth" "stalk-surface-below-ring=fibrous" #> [67] "stalk-surface-below-ring=scaly" "stalk-surface-below-ring=silky" #> [69] "stalk-surface-below-ring=smooth" "stalk-color-above-ring=brown" #> [71] "stalk-color-above-ring=buff" "stalk-color-above-ring=cinnamon" #> [73] "stalk-color-above-ring=gray" "stalk-color-above-ring=orange" #> [75] "stalk-color-above-ring=pink" "stalk-color-above-ring=red" #> [77] "stalk-color-above-ring=white" "stalk-color-above-ring=yellow" #> [79] "stalk-color-below-ring=brown" "stalk-color-below-ring=buff" #> [81] "stalk-color-below-ring=cinnamon" "stalk-color-below-ring=gray" #> [83] "stalk-color-below-ring=orange" "stalk-color-below-ring=pink" #> [85] "stalk-color-below-ring=red" "stalk-color-below-ring=white" #> [87] "stalk-color-below-ring=yellow" "veil-type=partial" #> [89] "veil-type=universal" "veil-color=brown" #> [91] "veil-color=orange" "veil-color=white" #> [93] "veil-color=yellow" "ring-number=none" #> [95] "ring-number=one" "ring-number=two" #> [97] "ring-type=cobwebby" "ring-type=evanescent" #> [99] "ring-type=flaring" "ring-type=large" #> [101] "ring-type=none" "ring-type=pendant" #> [103] "ring-type=sheathing" "ring-type=zone" #> [105] "spore-print-color=black" "spore-print-color=brown" #> [107] "spore-print-color=buff" "spore-print-color=chocolate" #> [109] "spore-print-color=green" "spore-print-color=orange" #> [111] "spore-print-color=purple" "spore-print-color=white" #> [113] "spore-print-color=yellow" "population=abundant" #> [115] "population=clustered" "population=numerous" #> [117] "population=scattered" "population=several" #> [119] "population=solitary" "habitat=grasses" #> [121] "habitat=leaves" "habitat=meadows" #> [123] "habitat=paths" "habitat=urban" #> [125] "habitat=waste" "habitat=woods"
colnames(dtrain) <- make.names(1:ncol(train$data)) print(dtrain, verbose = TRUE)
#> <lgb.Dataset> #> Public: #> construct: function () #> create_valid: function (data, info = list(), ...) #> dim: function () #> finalize: function () #> get_colnames: function () #> getinfo: function (name) #> initialize: function (data, params = list(), reference = NULL, colnames = NULL, #> save_binary: function (fname) #> set_categorical_feature: function (categorical_feature) #> set_colnames: function (colnames) #> set_reference: function (reference) #> setinfo: function (name, info) #> slice: function (idxset, ...) #> update_params: function (params) #> Private: #> categorical_feature: NULL #> colnames: X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X ... #> free_raw_data: TRUE #> get_handle: function () #> handle: 9.82314123243107e-316 #> info: list #> params: list #> predictor: NULL #> raw_data: NULL #> reference: NULL #> set_predictor: function (predictor) #> used_indices: NULL