I just trained and performed prediction with a learner. He's good at predicting, so I wanted to keep and save it to use on new datas :
best_ranger<-bmr_ranger$score(msr("classif.bacc"))[learner_id == 'classif.ranger.tuned', ][classif.bacc == max(classif.bacc)]$learner[[1]]
saveRDS(best_ranger, 'learner_ranger.rds')
model <- readRDS('learner_ranger.rds')
As you can see, I selected my best model who gave me the best BACC on my test datas, following benchmarking. Then, I want to use it on completely new datas I just created. I didn't put weight, target or ordered columns role since it's completely new datas, the name of the other useful columns are the same :
data_total <- read.csv2("Radiomic.csv")%>%
dplyr::filter(!grepl("E1", rowname)) %>%
group_by(PatientID) %>%
dplyr::mutate(Lesions = n()) %>%
ungroup() %>%
fastDummies::dummy_cols(select_columns = "Loc_clean") %>%
dplyr::select(-Loc_clean) %>%
dplyr::rename_with(~ gsub("Loc_clean", "", .), starts_with("Loc_clean"))
colnames_to_keep <- colnames(data_top)
data_total <- data_total[, colnames(data_total) %in% colnames_to_keep]
predictions = model$predict_newdata(data_total)
The first part is a simple pre processing, the exact same pre processing as the datas I use to train, validate and test my model... And when I want to predict I have this error message :
Error: No task stored, and no task provided
4.
stop(simpleError(str_wrap(sprintf(msg, ...), width = wrap), call = NULL))
3.
stopf("No task stored, and no task provided")
2.
.__Learner__predict_newdata(self = self, private = private, super = super,
newdata = newdata, task = task)
1.
model$predict_newdata(data_total)
I don't understand since in the mlr3 book, page 31, it's clearly says that I don't need to transform my data in task !!
Where does it may come from for you ?
EDIT : Found the answer ! It's not written in the book but you must call the learner via the model registered :
model$model$learner$predict_newdata(newdata = data_total)
The explanation here https://github.com/mlr-org/mlr3/issues/601