-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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-package] R session crashes on iris example #3445
Comments
Hi @OldMortality , I can help you with this. Thanks for the repo and for using I've copied your code below, as that makes it a little easier for others to see and improves the relevance of search results in this repo reproducible example (click me)rm(list=ls())
library(lightgbm)
# We load the default iris dataset shipped with R
data(iris)
# We must convert factors to numeric
# They must be starting from number 0 to use multiclass
# For instance: 0, 1, 2, 3, 4, 5...
iris$Species <- as.numeric(as.factor(iris$Species)) - 1L
# prevent R-session from crashing: response must be a factor
# iris$Species <- as.factor(iris$Species)
# We cut the data set into 80% train and 20% validation
# The 10 last samples of each class are for validation
train <- as.matrix(iris[c(1L:40L, 51L:90L, 101L:140L), ])
test <- as.matrix(iris[c(41L:50L, 91L:100L, 141L:150L), ])
dtrain <- lgb.Dataset(data = train[, 1L:4L], label = train[, 5L])
dtest <- lgb.Dataset.create.valid(dtrain, data = test[, 1L:4L], label = test[, 5L])
valids <- list(test = dtest)
# Method 1 of training
params <- list(objective = "multiclass", metric = "multi_error", num_class = 3L)
model <- lgb.train(
params
, dtrain
, 100L
, valids
, min_data = 1L
, learning_rate = 1.0
, early_stopping_rounds = 10L
)
s# We can predict on test data, outputs a 90-length vector
# Order: obs1 class1, obs1 class2, obs1 class3, obs2 class1, obs2 class2, obs2 class3...
my_preds <- predict(model, test[, 1L:4L])
# Method 2 of training, identical
model <- lgb.train(
list()
, dtrain
, 100L
, valids
, min_data = 1L
, learning_rate = 1.0
, early_stopping_rounds = 10L
, objective = "multiclass"
, metric = "multi_error"
, num_class = 3L
)
# We can predict on test data, identical
my_preds <- predict(model, test[, 1L:4L])
# A (30x3) matrix with the predictions, use parameter reshape
# class1 class2 class3
# obs1 obs1 obs1
# obs2 obs2 obs2
# .... .... ....
my_preds <- predict(model, test[, 1L:4L], reshape = TRUE) and the screenshot: I'll try running this on my Windows laptop later tonight, and let you know if I'm able to reproduce it. In the meantime, you could check if any of the recent bugfixes in this repo happened to fix the problem you're facing, by installing from our latest submission to CRAN: remotes::install_url("https://github.com/microsoft/LightGBM/files/5303046/lightgbm_3.0.0.2.tar.gz") Please let me know if that fixes your problem. I'll respond later with the results of my attempt to reproduce this. |
Hi, Thank you very much for your help with this. |
I tested on my Windows laptop tonight (Windows 10, RStudio 1.2.5019, R 4.0.2). I have good news and bad news: bad news When In installed like this remove.packages("lightgbm")
remotes::install_url("https://github.com/microsoft/LightGBM/files/5303046/lightgbm_3.0.0.2.tar.gz") And then ran the code you provided, my RStudio session did crash in the first call to good news When I restarted my R session and ran the sample code from the beginning. It all succeeded without error! I repeated this three times, and it worked each time. Can you please try restarting your R session in RStudio and re-running the code? I wonder if something about the way |
I have done better than restarting the R-session: I restarted the computer! But to no avail. |
Well, I restarted R, and did:
and then I still had the error. So that's great. It is getting a little late here in New Zealand, so I'll leave it for today. Many thanks for your help. I very much appreciate it, because I was entirely stuck with this. Cheers, Michel |
The problem first arose because I had a bug in the code. I seem to have an infinite loop (or a Very Long Loop) and I had interrupted RStudio through the task manager, and that then leaves lightgbm in a bad state. Even though there is a workaround, it would be great to have a fix, because I cannot re-install lightgbm, reload the data, and rerun everything every time I try to fix this bug. |
You shouldn't have to re-install lightgbm. For me, it was enough to just install it one time, then restart my R session. Ater that, every new session should work with just |
Great, thank you. It is all working for me now. Many thanks for you help. |
oh good, I'm glad! Thanks for using |
This issue has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
R crashes when I get to lgb.train statement.
This is happening in my project, but I can recreate it in the iris example (attached)
I will attach the code, and a screenshot of the error.
This has worked for me before, I don't know what has changed.
lightgbm R fatal error.zip
The FAQ says I may ping a member with the relevant knowledge, so I will attempt to do this here: @guolinke @Laurae2
Many thanks for your attention.
I am using Windows 10, R version 4.0.2.
I installed the lightgbm package like this:
The text was updated successfully, but these errors were encountered: