This Issue had the same error but its resolution apparently doesn't apply - https://github.com/Microsoft/LightGBM/issues/219 . Please let me know if I should've made this a comment in that thread instead of opening it here.
Operating System: Windows Server 2008 R2
CPU: Intel
C++/Python/R version: R 3.3.1
api error: cannot open data file k
library(lightgbm)
data(ChickWeight) # Built in data set
ChickWeight <- sapply(ChickWeight, function(x) as.numeric(as.character(x)))
head(ChickWeight)
apply(ChickWeight,2,class)
y <- ChickWeight[,"weight"]
x <- ChickWeight[,!colnames(ChickWeight)=="weight"]
dtrain <- lgb.Dataset(data = as.matrix(x),
label = as.numeric(y),
free_raw_data=FALSE
)
lgb.Dataset.construct(dtrain)
Error in lgb.call("LGBM_DatasetCreateFromMat_R", ret = handle, private$raw_data, :
api error: cannot open data file k
It's only numeric data. I tried it with data.matrix instead of as.matrix. I also tried making it a sparse matrix first with a different input data set.
@hack-r can you try to reinstall LightGBM? It is working correctly here.
If you did not restart R, use lgb.unloader(wipe = TRUE) to kill lightgbm resources from R (you will have to redo library(lightgbm) to access LightGBM again. There are conflicts when you get an error and you do not reload lightgbm in R.
> library(lightgbm)
Loading required package: R6
> data(ChickWeight) # Built in data set
>
> ChickWeight <- sapply(ChickWeight, function(x) as.numeric(as.character(x)))
> head(ChickWeight)
weight Time Chick Diet
[1,] 42 0 1 1
[2,] 51 2 1 1
[3,] 59 4 1 1
[4,] 64 6 1 1
[5,] 76 8 1 1
[6,] 93 10 1 1
> apply(ChickWeight,2,class)
weight Time Chick Diet
"numeric" "numeric" "numeric" "numeric"
>
> y <- ChickWeight[,"weight"]
> x <- ChickWeight[,!colnames(ChickWeight)=="weight"]
>
> dtrain <- lgb.Dataset(data = as.matrix(x),
+ label = as.numeric(y),
+ free_raw_data=FALSE
+ )
>
> lgb.Dataset.construct(dtrain)
>
Thanks so much @Laurae2 . I did restart R before, but I didn't know about lgb.unloader(wipe = TRUE). That did the trick.
@Laurae2 's solution helped me in a similar instance as well.
@Laurae2 you save my day!
Most helpful comment
@hack-r can you try to reinstall LightGBM? It is working correctly here.
If you did not restart R, use
lgb.unloader(wipe = TRUE)to killlightgbmresources from R (you will have to redolibrary(lightgbm)to access LightGBM again. There are conflicts when you get an error and you do not reload lightgbm in R.