LightGBM icon indicating copy to clipboard operation
LightGBM copied to clipboard

R error : Unknown parameter: nrounds

Open klyan opened this issue 9 years ago • 16 comments

Error Message:

dtrain <- lgb.Dataset(as.matrix(train.data), label = train.label) dtest <- lgb.Dataset(as.matrix(test.data), label = test.label) params <- list(objective = "lambdarank", metric = "ndcg", ndcg_eval_at = 1,3,5,7,10, max_depth = 3, verbose = 1, num_threads = 10) model <- lgb.train(params, data = dtrain, nrounds = 300, learning_rate = 0.1, early_stopping_rounds = 10, weight=train.weight, group = train.group)

[LightGBM] [Fatal] Unknown parameter: nrounds Error in lgb.call("LGBM_DatasetCreateFromMat_R", ret = handle, private$raw_data, : api error: Unknown parameter: nrounds

Are there any errors in my parameter config??

klyan avatar Jul 17 '17 03:07 klyan

I repace "nrounds" with "num_trees" or "num_iterations", even remove nrounds parameter, it doesn't work. How could I control the iterations for lambdarank?

model <- lgb.train(params, data = dtrain, num_iterations = 300, learning_rate = 0.1, early_stopping_rounds = 10, weight=train.weight, group = train.group) [LightGBM] [Fatal] Unknown parameter: nrounds Error in lgb.call("LGBM_DatasetCreateFromMat_R", ret = handle, private$raw_data, : api error: Unknown parameter: nrounds model <- lgb.train(params, data = dtrain, learning_rate = 0.1, early_stopping_rounds = 10, weight=train.weight, group = train.group) [LightGBM] [Fatal] Unknown parameter: nrounds Error in lgb.call("LGBM_DatasetCreateFromMat_R", ret = handle, private$raw_data, : api error: Unknown parameter: nrounds

klyan avatar Jul 17 '17 03:07 klyan

@klyan nrounds should work, I just test it. Maybe you need to restart R. And you also can try model <- lgb.train(params, dtrain, 300, learning_rate = 0.1, early_stopping_rounds = 10, weight=train.weight, group = train.group)

guolinke avatar Jul 17 '17 03:07 guolinke

I restarted R, But it still doesn't work for me.

R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree" Copyright (C) 2015 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R.

library("xgboost") library("rjson") library("stringi") library("caTools") library("lightgbm") Loading required package: R6

Attaching package: ‘lightgbm’

The following objects are masked from ‘package:xgboost’:

getinfo, setinfo, slice

load("ligbm.RData") params <- list(objective = "lambdarank", metric = "ndcg", ndcg_eval_at = 1,3,5,7,10, max_depth = 3, verbose = 1, num_threads = 10) model <- lgb.train(params, data = dtrain, nrounds = 300, learning_rate = 0.1, early_stopping_rounds = 10, weight=train.weight, group = train.group) [LightGBM] [Fatal] Unknown parameter: nrounds Error in lgb.call("LGBM_DatasetCreateFromMat_R", ret = handle, private$raw_data, : api error: Unknown parameter: nrounds

klyan avatar Jul 17 '17 03:07 klyan

@Laurae2 any ideas ? it seems the nrounds parameter is not captured correctly. Maybe the reason is the version of R is too old.

@klyan another problem is you cannot use early_stopping_rounds if you don't pass the validation data in lgb.train .

guolinke avatar Jul 17 '17 03:07 guolinke

@klyan and the weight and group is the parameter of lgb.Dataset, not the lgb.train.

guolinke avatar Jul 17 '17 03:07 guolinke

@guolinke Seems the parameters passed in params are not correct (like ndcg_eval_at)

Laurae2 avatar Jul 17 '17 05:07 Laurae2

@klyan Can you provide a reproducible example so we can test?

Laurae2 avatar Jul 17 '17 05:07 Laurae2

@Laurae2 @guolinke The fowllowing script is my code. The training data have 3 labels: 0 for view, 0.6 for click but not ordered, 1 for ordered. Then I set the training weight 30 for ordered sample. I have fixed the ndcg_eval_at, weight and group parameters in my code. Still doesn't work. Thanks you very much!

library("lightgbm")

csvdata <- read.csv("/data/pairwise/train1.csv",sep='\t') csvdata1 <- read.csv("/data/pairwise/test.csv",sep='\t')

#selected features for training removecol <- c("modelscore","dpid","shop_id","label","real_order","groupcnt") train.data <- csvdata[,which(!colnames(csvdata) %in% removecol)] test.data <- csvdata1[,which(!colnames(csvdata1) %in% removecol)]

#set 3 label; view:0 click_notorder:0.6 order:1 csvdata[csvdata[,"real_order"] == 0 & csvdata[,"label"] == 1,"real_order"] <- 0.6 csvdata1[csvdata1[,"real_order"] == 0 & csvdata1[,"label"] == 1,"real_order"] <- 0.6 train.label <- csvdata$real_order
test.label <- csvdata1$real_order

#set group by userid(query) train.group <- unique(csvdata[,c("dpid","groupcnt")]) test.group <- unique(csvdata1[,c("dpid","groupcnt")]) train.group <- train.group[,"groupcnt"] test.group <- test.group[,"groupcnt"]

#set sample weight train.weight <- rep(1,nrow(csvdata)) train.weight[csvdata$real_order == 1] <- 30 test.weight <- rep(1,nrow(csvdata1)) test.weight[csvdata1$real_order == 1] <- 30

dtrain <- lgb.Dataset(as.matrix(train.data), label = train.label, weight=train.weight, group = train.group) dtest <- lgb.Dataset(as.matrix(test.data), label = test.label)

params <- list(objective = "lambdarank", metric = "ndcg", max_depth = 3, verbose = 1, num_threads = 10) model <- lgb.train(params, data = dtrain, nrounds = 300, learning_rate = 0.1)

klyan avatar Jul 17 '17 05:07 klyan

@klyan we cannot reproduce it since we don't have your data. you can use agaricus data:

data(agaricus.train, package = "lightgbm")
data(agaricus.test, package = "lightgbm")
train <- agaricus.train
test <- agaricus.test

Also, you can format your code for the better readability .

I also try some other cases, but still not met your problem.

guolinke avatar Jul 17 '17 13:07 guolinke

@klyan updates ?

guolinke avatar Jul 19 '17 08:07 guolinke

try nround=300

zheguzai100 avatar Jul 19 '17 08:07 zheguzai100

@guolinke Sorry, it's too big to upload my data. And I try my data in latest R version in MacOS, get the same error. But python package is OK for me.(I have updated my code, above) . Thanks a lot! @zheguzai100 'nround' doesn't work

klyan avatar Jul 19 '17 09:07 klyan

@klyan can you try it without using group, and change objective to regression ?

guolinke avatar Jul 19 '17 09:07 guolinke

@guolinke Yes! it works!

lgb.unloader(wipe = TRUE)

makes both of them work. It seems that somes errors in my environment. And I save variable into RData, then restart my R. But doesn't fix it and 'lgb.unloader(wipe = TRUE)' fix it

klyan avatar Jul 19 '17 09:07 klyan

@Laurae2 It seems the R-package often have some random issues. maybe we should add the solution to the documents.

guolinke avatar Jul 19 '17 10:07 guolinke

Maybe (one) of the reasons is the following code snipped from lgb.train:

if (sum(names(params) %in% c("num_iterations", "num_iteration", 
        "num_tree", "num_trees", "num_round", "num_rounds")) > 
        0) {
        end_iteration <- begin_iteration + params[[which(names(params) %in% 
            c("num_iterations", "num_iteration", "num_tree", 
                "num_trees", "num_round", "num_rounds"))[1]]] - 
            1
    }
    else {
        end_iteration <- begin_iteration + nrounds - 1
    }

No matter if you pass nrounds in the params list or as a separate argument to lgb.train, you will always end up in the else branch and, if nrounds was specified in params, the default of 10 will be used.

Fixing this won't solve the problem, which is hidden in the call to LGBM_DatasetCreateFromCSC_R. But maybe it is still worth a look.

mayer79 avatar Sep 27 '17 21:09 mayer79