Skip to content
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 predict in new data in mlr3 0.20.0 #1049

Closed
DylanGuo1101 opened this issue Jul 17, 2024 · 3 comments
Closed

How to predict in new data in mlr3 0.20.0 #1049

DylanGuo1101 opened this issue Jul 17, 2024 · 3 comments

Comments

@DylanGuo1101
Copy link

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

@be-marc
Copy link
Sponsor Member

be-marc commented Jul 23, 2024

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.

@be-marc
Copy link
Sponsor Member

be-marc commented Jul 23, 2024

Please reopen if the issue persist.

@be-marc be-marc closed this as completed Jul 23, 2024
@DylanGuo1101
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants