0

I am new to lightgbm package I am trying to build linear regression model with following sample train data having medianhousevalue as response variable in rstudio

housingMedianAge    totalRooms  totalBedrooms   population  households  medianIncome    medianHouseValue
41  880 129 322 126 8.3252  452600
21  7099    1106    2401    1138    8.3014  358500
52  1467    190 496 177 7.2574  352100
52  1274    235 558 219 5.6431  341300
52  1627    280 565 259 3.8462  342200
52  919 213 413 193 4.0368  269700
52  2535    489 1094    514 3.6591  299200
52  3104    687 1157    647 3.12    241400
42  2555    665 1206    595 2.0804  226700
52  3549    707 1551    714 3.6912  261100
52  2202    434 910 402 3.2031  281500
52  3503    752 1504    734 3.2705  241800
52  2491    474 1098    468 3.075   213500
52  696 191 345 174 2.6736  191300
52  2643    626 1212    620 1.9167  159200
50  1120    283 697 264 2.125   140000

and the sample testdata is

50  2239    455 990 419 1.9911
52  1503    298 690 275 2.6033
40  751 184 409 166 1.3578
42  1639    367 929 366 1.7135
52  2436    541 1015    478 1.725
52  1688    337 853 325 2.1806
52  2224    437 1006    422 2.6

pls share the code to build the model in lightgbm with params list to predict the output.

edit: Moved information from comment to question

train <- as.matrix (train) 
test <- as.matrix(test) 
dtrain <- lgb.Dataset(data = train(,1:5), label = train[, 6]) 
params <- list(objective = "regression ", metric = "l2" ) 
model <- lgb.train(params, train, 100, valids, min_data = 1, learning_rate = 1, early_stopping_rounds = 10) 

after there is an error related to train data frame it has to be in Dgcmatrix

phiver
  • 23,048
  • 14
  • 44
  • 56
vijaynadal
  • 55
  • 5
  • What have you done till now? please share your work. – MKR Jan 25 '18 at 14:18
  • train <-as.matrix (train) test <- as.matrix(test) dtrain <- lgb.Dataset(data = train(,1:5), label = train[, 6]) params <- list(objective = "regression ", metric = "l2" ) model <- lgb.train(params, train, 100, valids, min_data = 1, learning_rate = 1, early_stopping_rounds = 10) after there is an error related to train data frame it has to be in Dgcmatrix – vijaynadal Jan 25 '18 at 15:21

1 Answers1

1

For line 3, replace

train(,1:5)

with

train[,1:5]

(square brackets)

moc
  • 26
  • 6