Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 208914

Error running LightGBM in R "does not support constructing from ‘data.frame’"

$
0
0

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.


Viewing all articles
Browse latest Browse all 208914

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>