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

Dissemination: SuperLearner -> sl3 translation guide #122

Open
nhejazi opened this issue Mar 19, 2018 · 0 comments
Open

Dissemination: SuperLearner -> sl3 translation guide #122

nhejazi opened this issue Mar 19, 2018 · 0 comments

Comments

@nhejazi
Copy link
Member

nhejazi commented Mar 19, 2018

In order to help with user migration, it would be really nice to have a "translation guide" for experienced users of the SuperLearner package to use sl3. This would take the place of a "SuperLearner3()" style wrapper function, instead helping users to find the correct sl3 idiom(s) to use in place of a given SuperLearner function or argument. An example of such would be the following:

library(SuperLearner)
library(sl3)
set.seed(57192)

# toy data
n <- 1000
p <- 3
x <- as.data.frame(replicate(p, rnorm(n, mean = 0, sd = 1)))
y <- sin(x[, 1]) + x[, 2] + rnorm(n, mean = 0, sd = 0.3)
dat <- as.data.frame(cbind(x, y))

# using SuperLearner
sl_lib <- c("SL.mean", "SL.glm")
sl_old <- SuperLearner(Y = y, X = x, SL.library = sl_lib)
y_pred_old <- predict(sl_old)$pred

# using sl3
sl_task <- make_sl3_Task(covariates = colnames(dat)[seq_len(p)], outcome = "y", data = dat)
sl3_lib <- make_learner_stack("Lrnr_mean", "Lrnr_glm_fast")
sl_new <- Lrnr_sl$new(learners = sl3_lib, metalearner = Lrnr_nnls$new())
sl_trained <- sl_new$train(sl_task)
y_pred_new <- sl_trained$predict()

# squared error difference
mean((y_pred_old - y_pred_new)^2)

...with the point being that an experience user (of SuperLearner, new to sl3) would be able to easily pick up the similarities between, for example, make_learner_stack and SL.library or calling the R6 .$predict method of the trained sl3 model vs. the S3 predict(...) method for an object of class SuperLearner. This is just an early-stage idea and could definitely use refinement and input from further discussion.

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

No branches or pull requests

2 participants