-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
How to fix “DMatrix/Booster has not been initialized or has already been disposed. is:closed” #400
Comments
Thanks for this bug report! For a workaround, I think you can do: library(mlr3)
library(mlrproba)
library(mlr3verse)
library(mlr3extralearners)
library(xgboost)
task = as_task("lung")
learner = lrn("surv.xgboost.cox")$train(task)
saveRDS(learner,"learner.rds")
xgb.save(learner$model$model, "xgb.model") and then: learner = readRDS("learner.rds")
model = xgb.load("xgb.model")
learner$model$model = model let me know whether this works for you |
Thanks! But:
Packages version is [1] dplyr_1.1.4 xgboost_1.7.7.1 mlr3proba_0.6.9 mlr3verse_0.3.0 mlr3tuning_1.0.0 paradox_1.0.1 |
Ok, we need to do the same for the library(survival)
library(mlr3)
library(mlr3proba)
library(mlr3verse)
library(mlr3extralearners)
library(xgboost)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following object is masked from 'package:xgboost':
#>
#> slice
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
lung_filter = lung |> select(-sex,-ph.ecog)
task = TaskSurv$new(id="lung",backend = lung_filter,time = "time",event = "status")
learner = lrn("surv.xgboost.cox")$train(task)
saveRDS(task,"task.rds")
saveRDS(learner,"learner.rds")
xgb.save(learner$model$model, "xgb.model")
#> [1] TRUE
xgb.DMatrix.save(learner$model$train_data, "xgb.data")
#> [1] TRUE
learner = readRDS("learner.rds")
learner$model$model = xgb.load("xgb.model")
learner$model$train_data = xgb.DMatrix("xgb.data")
#> [07:24:06] 228x6 matrix with 1302 entries loaded from xgb.data
# [1] TRUE
learner$predict_newdata(lung_filter,task)
#> <PredictionSurv> for 228 observations:
#> row_ids time status crank lp distr
#> 1 306 TRUE 65.82970 65.82970 <list[1]>
#> 2 455 TRUE 65.80392 65.80392 <list[1]>
#> 3 1010 FALSE 59.49477 59.49477 <list[1]>
#> --- --- --- --- --- ---
#> 226 105 FALSE 57.72884 57.72884 <list[1]>
#> 227 174 FALSE 63.40212 63.40212 <list[1]>
#> 228 177 FALSE 61.15349 61.15349 <list[1]> Created on 2024-12-06 with reprex v2.1.1 |
In fact, you only need to do it for the library(survival)
library(mlr3)
library(mlr3proba)
library(mlr3verse)
library(mlr3extralearners)
library(xgboost)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following object is masked from 'package:xgboost':
#>
#> slice
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
lung_filter = lung |> select(-sex,-ph.ecog)
task = TaskSurv$new(id="lung",backend = lung_filter,time = "time",event = "status")
learner = lrn("surv.xgboost.cox")$train(task)
saveRDS(task,"task.rds")
saveRDS(learner,"learner.rds")
xgb.save(learner$model$model, "xgb.model")
#> [1] TRUE
xgb.DMatrix.save(learner$model$train_data, "xgb.data")
#> [1] TRUE
learner = readRDS("learner.rds")
learner$model$train_data = xgb.DMatrix("xgb.data")
#> [08:07:24] 228x6 matrix with 1302 entries loaded from xgb.data
# [1] TRUE
learner$predict_newdata(lung_filter,task)
#> <PredictionSurv> for 228 observations:
#> row_ids time status crank lp distr
#> 1 306 TRUE 65.82970 65.82970 <list[1]>
#> 2 455 TRUE 65.80392 65.80392 <list[1]>
#> 3 1010 FALSE 59.49477 59.49477 <list[1]>
#> --- --- --- --- --- ---
#> 226 105 FALSE 57.72884 57.72884 <list[1]>
#> 227 174 FALSE 63.40212 63.40212 <list[1]>
#> 228 177 FALSE 61.15349 61.15349 <list[1]> Created on 2024-12-06 with reprex v2.1.1 |
Oh, it works!!!! Thank you so much for your help—I really appreciate it! 😊 |
we should fix this with marshalling |
Description
src/c_api/c_api.cc:675: DMatrix/Booster has not been initialized or has already been disposed. This happened PipeOp surv.xgboost.cox's $predict()
Reproducible example
I trained an xgboost.cox for mlr3prob and mlr3extralearners and I saved it (RDS). Then I copied it to my another system to predict new data. But error comes up:
src/c_api/c_api.cc:675: DMatrix/Booster has not been initialized or has already been disposed. This happened PipeOp surv.xgboost.cox's $predict()
Thanks for help!!! 😊
I used R-4.2.3 and mlrextralearner 1.0.0 and the version of mlr3prob is 0.6.9
Like this
=============================
another file
Error in dim.xgb.DMatrix(x) :
[17:45:16] src/c_api/c_api.cc:675: DMatrix/Booster has not been initialized or has already been disposed.
This happened PipeOp surv.xgboost.cox's $predict()
Additionally: Warning message:
In warn_deprecated("Learner$data_formats") :
Learner$data_formats is deprecated and will be removed in the future.
The text was updated successfully, but these errors were encountered: