I finally installed LightGBM in R, but I can't quite get it to work. Below is a simple reproducible example using the iris dataset.
I'm using R version 3.5.2 on windows 10 and lightgbm_2.2.4.
library(lightgbm)
library(caTools)
set.seed(42)
# Prepare the dataset for binary classification
iris$label <- 0
iris$label[iris$Species=="setosa"] <- 1
iris <- iris[,!(names(iris) %in% "Species")]
# Split into train & validation set
sample <- sample.split(iris$label, SplitRatio = .75)
train <- subset(iris, sample == TRUE)
valid <- subset(iris, sample == FALSE)
X_train <- train[,!(names(train) %in% "label")]
X_valid <- valid[,!(names(valid) %in% "label")]
y_train <- train$label
y_valid <- valid$label
# Train LightGBM
dtrain <- lgb.Dataset(data = X_train, label = y_train)
dvalid <- lgb.Dataset(data = X_valid, label = y_valid)
params <- list(objective = "binary",
verbose = 1,
seed = 42)
lgb_model <- lgb.train(params, dtrain, 200, list(eval = dvalid),
verbose_eval=200, early_stopping_round=10)
When runnning lgb.train, I get the following error message: "Error in data$construct() : lgb.Dataset.construct: does not support constructing from ‘data.frame’".
I can't figure out what is causing this error and how to fix it. Any help is greatly appreciated.