Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R error : Unknown parameter: nrounds #698

Closed
klyan opened this issue Jul 17, 2017 · 16 comments · Fixed by #712
Closed

R error : Unknown parameter: nrounds #698

klyan opened this issue Jul 17, 2017 · 16 comments · Fixed by #712

Comments

@klyan
Copy link

klyan commented Jul 17, 2017

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
Copy link
Author

klyan commented Jul 17, 2017

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

@guolinke
Copy link
Collaborator

@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)

@klyan
Copy link
Author

klyan commented Jul 17, 2017

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

@guolinke
Copy link
Collaborator

@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
Copy link
Collaborator

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

@Laurae2
Copy link
Contributor

Laurae2 commented Jul 17, 2017

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

@Laurae2
Copy link
Contributor

Laurae2 commented Jul 17, 2017

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

@klyan
Copy link
Author

klyan commented Jul 17, 2017

@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)

@guolinke
Copy link
Collaborator

@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
Copy link
Collaborator

@klyan updates ?

@zheguzai100
Copy link

try nround=300

@klyan
Copy link
Author

klyan commented Jul 19, 2017

@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

@guolinke
Copy link
Collaborator

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

@klyan
Copy link
Author

klyan commented Jul 19, 2017

@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

@guolinke
Copy link
Collaborator

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

@mayer79
Copy link
Contributor

mayer79 commented Sep 27, 2017

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.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants