Closed DylanGuo1101 closed 1 month ago
I see that you load a learner from disk. I assume this learner was created with an older mlr3 version? If you train the model with the version you are predicting with, there should be no problems. The error message points to a recent change in mlr3.
Please reopen if the issue persist.
I see that you load a learner from disk. I assume this learner was created with an older mlr3 version? If you train the model with the version you are predicting with, there should be no problems. The error message points to a recent change in mlr3.
Thank you!I have solved this problem after retraining the model.
I recently updated mlr3 to the latest version.
I used to predict new data with a trained model (lrn.rf) in mlr3 0.18.0 using the following code, and it worked fine. However, when I use the same code in mlr3 0.20.0, I receive the error: "Error: Setting row roles 'test'/'holdout' is no longer possible."
How can I predict new data without a target in mlr3 0.20.0?
Thank you!
lrn.rf <- readRDS('./aHCC-ML/tuned_RandomForest_model.rds')
dd <- data.frame( target = NA, Sex = 'Female', Age = 80, HBsAg = 'Positive', PLT = 44, AST = 20, AFP = 20, stringsAsFactors = FALSE ) |> as_tibble() |> mutate( HBsAg = case_when( HBsAg == 'Positive' ~ '1', HBsAg == 'Negative' ~ '0' ), Sex = case_when( Sex == 'Female' ~ '1', Sex == 'Male' ~ '0' ) ) |> mutate(across(c(Sex, HBsAg), factor))
res <- predict(lrn.rf, dd, predict_type = "prob")
Error: Setting row roles 'test'/'holdout' is no longer possible.task <- TaskClassif$new("test", backend = dd, target = "target")
Error: Target column 'target' must be a factor or ordered factor