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

Problem when predicting from loaded SL object #144

Open
tkasci opened this issue Sep 3, 2022 · 1 comment
Open

Problem when predicting from loaded SL object #144

tkasci opened this issue Sep 3, 2022 · 1 comment

Comments

@tkasci
Copy link

tkasci commented Sep 3, 2022

Hi, I built an SL model and saved it to disk. However, it contains a BART learner, so I get this error when trying to do anything with it:

Error in check_serialization(object) : 
  This bartMachine object was loaded from an R image but was not serialized.
  Please build bartMachine using the option "serialize = TRUE" next time.

What would be the best way to fix this? Is there a way to pass options to individual commands via SuperLearner?

@ecpolley
Copy link
Owner

ecpolley commented Sep 6, 2022

Hi, you might need to modify the SL.bartMachine wrapper to add the serialize = TRUE argument and retrain the SL model. Here is an example new wrapper (and then use SL.mybartMachine in the SL.library):

SL.mybartMachine <- function(Y, X, newX, family, obsWeights, id, num_trees = 50, 
    num_burn_in = 250, verbose = FALSE, alpha = 0.95, beta = 2, k = 2, 
    q = 0.9, nu = 3, num_iterations_after_burn_in = 1000, ...) 
{
require("bartMachine")
model = bartMachine::bartMachine(X = X, 
								y = Y, 
								num_trees = num_trees, 
    							num_burn_in = num_burn_in, 
    							verbose = verbose, 
    							alpha = alpha, 
    							beta = beta, 
    							k = k, 
    							q = q, 
    							nu = nu, 
    							num_iterations_after_burn_in = num_iterations_after_burn_in,
    							serialize = TRUE)
    pred <- predict(model, newX)
    fit <- list(object = model)
    class(fit) <- c("SL.bartMachine")
    out <- list(pred = pred, fit = fit)
    return(out)
}

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