### Install SuperLearner from GitHub Source: https://github.com/ecpolley/superlearner/blob/master/README.md Use this command to install the development version of the SuperLearner package from GitHub using the 'remotes' package. ```r # install.packages("remotes") remotes::install_github("ecpolley/SuperLearner") ``` -------------------------------- ### Install SuperLearner Package Source: https://context7.com/ecpolley/superlearner/llms.txt Installs the stable release from CRAN or the development version from GitHub. Loads the library for use. ```r # Install stable release from CRAN install.packages("SuperLearner") # Install development version from GitHub # install.packages("remotes") remotes::install_github("ecpolley/SuperLearner") library(SuperLearner) ``` -------------------------------- ### Install SuperLearner from CRAN Source: https://github.com/ecpolley/superlearner/wiki/Where-is-the-Windows-Binary? Use this command to install the SuperLearner package from CRAN within an R session. This is the recommended method for obtaining the Windows binary. ```R install.packages("SuperLearner") ``` -------------------------------- ### Open SuperLearner Vignette Source: https://github.com/ecpolley/superlearner/blob/master/README.md Opens the package vignette for SuperLearner, providing more detailed examples and explanations of its usage. ```r vignette(package = "SuperLearner") ``` -------------------------------- ### Create XGBoost Learners with Hyperparameter Grid Source: https://context7.com/ecpolley/superlearner/llms.txt Generates XGBoost learner configurations using `create.SL.xgboost` with specified hyperparameters. Creates a dedicated environment (`sl_env`) to store wrapper functions, keeping the global environment clean. Attach the environment before fitting the SuperLearner model and detach afterward. ```r library(SuperLearner) data(Boston, package = "MASS") set.seed(1) # Create a dedicated environment to keep global environment clean sl_env <- new.env() # 2 x 2 x 3 = 12 XGBoost configurations xgb_grid <- create.SL.xgboost( tune = list( ntrees = c(100, 500), max_depth = c(2, 4), shrinkage = c(0.1, 0.01, 0.001), minobspernode = 10 ), detailed_names = TRUE, env = sl_env, name_prefix = "SL.xgb" ) # Review configurations xgb_grid$grid # ntrees max_depth shrinkage minobspernode # 1 100 2 0.100 10 # 2 500 2 0.100 10 # ... # Attach environment so SuperLearner can find the wrapper functions attach(sl_env) sl_xgb <- SuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = c("SL.mean", xgb_grid$names), family = gaussian() ) sl_xgb detach(sl_env) ``` -------------------------------- ### Define a Custom Learner using SL.template Interface Source: https://context7.com/ecpolley/superlearner/llms.txt Demonstrates how to add any R function conforming to the `SL.template` interface to the SuperLearner library. The learner must accept `(Y, X, newX, family, obsWeights, id, ...)` and return a list with `$pred` and `$fit`. A corresponding `predict.SL.*` function is also required. ```r library(SuperLearner) ``` -------------------------------- ### Customizing SuperLearner Controls Source: https://context7.com/ecpolley/superlearner/llms.txt Illustrates using SuperLearner.control() and SuperLearner.CV.control() for fine-grained control over model fitting and cross-validation. Requires the MASS package. ```r library(SuperLearner) data(Boston, package = "MASS") set.seed(1) # SuperLearner.control: controls library persistence and log-odds trimming ctrl <- SuperLearner.control( saveFitLibrary = TRUE, # save fitted model objects (needed for predict()) saveCVFitLibrary = FALSE, # save CV fold model objects (memory-intensive) trimLogit = 0.001 # trim predicted probabilities away from 0/1 ) # SuperLearner.CV.control: controls cross-validation splitting cv_ctrl <- SuperLearner.CV.control( V = 10L, # number of folds stratifyCV = FALSE, # set TRUE for stratified folds (binary outcomes) shuffle = TRUE, # shuffle rows before assigning folds validRows = NULL # or pass a pre-specified list of row-index vectors ) sl_ctrl <- SuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = c("SL.glmnet", "SL.randomForest", "SL.lm"), family = gaussian(), control = ctrl, cvControl = cv_ctrl ) # When saveFitLibrary = FALSE, predict() on new data will error # sl_ctrl$control$saveFitLibrary # TRUE ``` -------------------------------- ### Hyperparameter Optimization with SuperLearner Source: https://github.com/ecpolley/superlearner/blob/master/README.md Demonstrates hyperparameter optimization for the 'SL.glmnet' learner, specifically tuning the 'alpha' parameter to explore different elastic net regularization strengths. It then fits a SuperLearner ensemble including the tuned elastic net. ```r # Hyperparameter optimization -- # Fit elastic net with 5 different alphas: 0, 0.2, 0.4, 0.6, 0.8, 1.0. # 0 corresponds to ridge and 1 to lasso. enet = create.Learner("SL.glmnet", detailed_names = T, tune = list(alpha = seq(0, 1, length.out = 5))) sl_lib2 = c("SL.mean", "SL.lm", enet$names) enet_sl = SuperLearner(Y = Boston$medv, X = Boston[, -14], SL.library = sl_lib2) # Identify the best-performing alpha value or use the automatic ensemble. enet_sl ``` -------------------------------- ### Binary Classification with SuperLearner Source: https://context7.com/ecpolley/superlearner/llms.txt Demonstrates binary classification using SuperLearner with family=binomial(). Optimizes for AUC using method.AUC. Requires the mlbench and cvAUC packages. ```r library(SuperLearner) data(PimaIndiansDiabetes2, package = "mlbench") dat <- na.omit(PimaIndiansDiabetes2) Y <- as.numeric(dat$diabetes == "pos") # 0/1 outcome X <- subset(dat, select = -diabetes) set.seed(1, "L'Ecuyer-CMRG") sl_bin <- SuperLearner( Y = Y, X = X, family = binomial(), SL.library = c("SL.mean", "SL.glm", "SL.glmnet", "SL.randomForest", "SL.xgboost"), method = "method.NNLS" # or method.AUC() to optimize AUC directly ) sl_bin # Predicted probabilities on training data probs <- sl_bin$SL.predict cat("Predicted probability range:",range(probs), "\n") # Evaluate AUC library(cvAUC) AUC(predictions = probs, labels = Y) # [1] 0.86 # External CV to get unbiased AUC estimate cv_sl_bin <- CV.SuperLearner( Y = Y, X = X, family = binomial(), SL.library = c("SL.mean", "SL.glm", "SL.glmnet", "SL.randomForest"), V = 5 ) summary(cv_sl_bin) ``` -------------------------------- ### Recombining SuperLearner Fits Source: https://context7.com/ecpolley/superlearner/llms.txt Shows how to use recombineSL() and recombineCVSL() to re-fit only the meta-learner step of an existing SuperLearner fit. This is efficient for exploring different combining strategies without refitting base learners. Requires the MASS package. ```r library(SuperLearner) data(Boston, package = "MASS") set.seed(1) # Initial fit with default NNLS sl_init <- SuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = c("SL.glmnet", "SL.randomForest", "SL.xgboost", "SL.lm"), family = gaussian() ) sl_init$coef # Re-combine using a different metalearner (no base learner refitting) sl_nnls2 <- recombineSL(sl_init, Y = Boston$medv, method = "method.NNLS2") sl_nnls2$coef # For CV.SuperLearner, use recombineCVSL cv_sl <- CV.SuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = c("SL.glmnet", "SL.randomForest", "SL.lm"), V = 5 ) cv_sl_nnls2 <- recombineCVSL(cv_sl, Y = Boston$medv, method = "method.NNLS2") summary(cv_sl_nnls2) ``` -------------------------------- ### Create Elastic Net Learners with Alpha Grid Search Source: https://context7.com/ecpolley/superlearner/llms.txt Generates multiple `SL.glmnet` learners with varying `alpha` values for hyperparameter tuning. `detailed_names = TRUE` creates names like `SL.glmnet_0`, `SL.glmnet_0.25`, etc. Ensure to remove created functions from the global environment after use. ```r library(SuperLearner) data(Boston, package = "MASS") set.seed(1) # --- Example 1: Elastic net with a grid of alpha values --- # Fits lasso (alpha=1), ridge (alpha=0), and three values in between enet_learners <- create.Learner( base_learner = "SL.glmnet", tune = list(alpha = seq(0, 1, length.out = 5)), detailed_names = TRUE # names like "SL.glmnet_0", "SL.glmnet_0.25", etc. ) enet_learners$names # [1] "SL.glmnet_0" "SL.glmnet_0.25" "SL.glmnet_0.5" # "SL.glmnet_0.75" "SL.glmnet_1" sl_enet <- SuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = c("SL.mean", "SL.lm", enet_learners$names), family = gaussian() ) sl_enet # Clean up created functions from global environment when done rm(list = enet_learners$names) ``` -------------------------------- ### Combine Screening Algorithms with Prediction Algorithms Source: https://context7.com/ecpolley/superlearner/llms.txt Specifies a SuperLearner library where prediction algorithms are paired with screening algorithms. Built-in screens include `screen.glmnet`, `screen.randomForest`, `screen.corP`, `screen.corRank`, and `screen.ttest`. The `sl_screen$libraryNames` will include the screen suffix, and `sl_screen$whichScreen` provides a logical matrix indicating selected variables. ```r library(SuperLearner) data(Boston, package = "MASS") set.seed(1) # Combine screening with prediction algorithms # Each inner vector: c(learner, screen) sl_lib_screened <- list( c("SL.glmnet", "All"), # no screening c("SL.randomForest", "All"), c("SL.glm", "screen.glmnet"), # lasso-selected features → GLM c("SL.lm", "screen.corP"), # top p-value features → OLS c("SL.xgboost", "screen.randomForest") # RF-selected features → XGBoost ) sl_screen <- SuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = sl_lib_screened, family = gaussian() ) # Library names include screen suffix sl_screen$libraryNames # [1] "SL.glmnet_All" "SL.randomForest_All" # "SL.glm_screen.glmnet" "SL.lm_screen.corP" # "SL.xgboost_screen.randomForest" sl_screen$whichScreen # logical matrix: kScreen x p, TRUE = variable selected ``` -------------------------------- ### Define Custom Ridge Regression Learner for SuperLearner Source: https://context7.com/ecpolley/superlearner/llms.txt Implement a custom penalized ridge regression learner by defining SL.myRidge and its corresponding predict method. This allows integration into the SuperLearner ensemble. ```R SL.myRidge <- function(Y, X, newX, family, obsWeights, id, lambda = 1, ...) { require(glmnet) if (!is.matrix(X)) X <- model.matrix(~ -1 + ., X) if (!is.matrix(newX)) newX <- model.matrix(~ -1 + ., newX) fit_obj <- glmnet::glmnet(x = X, y = Y, alpha = 0, lambda = lambda, family = family$family, weights = obsWeights) pred <- as.numeric(predict(fit_obj, newx = newX, type = "response")) fit <- list(object = fit_obj, lambda = lambda) class(fit) <- "SL.myRidge" return(list(pred = pred, fit = fit)) } ``` ```R predict.SL.myRidge <- function(object, newdata, ...) { if (!is.matrix(newdata)) newdata <- model.matrix(~ -1 + ., newdata) as.numeric(predict(object$object, newx = newdata, s = object$lambda, type = "response")) } ``` ```R data(Boston, package = "MASS") set.seed(1) sl_custom <- SuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = c("SL.mean", "SL.lm", "SL.myRidge", "SL.glmnet"), family = gaussian() ) sl_custom$coef ``` -------------------------------- ### Parallel Cross-Validation with CV.SuperLearner Source: https://context7.com/ecpolley/superlearner/llms.txt Perform parallel cross-validation using CV.SuperLearner with options for multicore (Unix/macOS) or PSOCK clusters (Windows-compatible). This is the recommended method for evaluating SuperLearner's generalization error. ```R library(SuperLearner) library(parallel) data(Boston, package = "MASS") set.seed(1) sl_lib <- c("SL.glmnet", "SL.randomForest", "SL.xgboost", "SL.mean") # --- Option 1: multicore (fork-based, Unix/macOS) --- cv_sl_mc <- CV.SuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = sl_lib, family = gaussian(), V = 5, parallel = "multicore" ) # --- Option 2: PSOCK cluster (Windows-compatible) --- cl <- makeCluster(4, type = "PSOCK") clusterSetRNGStream(cl, iseed = 42) cv_sl_cl <- CV.SuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = sl_lib, family = gaussian(), V = 5, parallel = cl ) stopCluster(cl) summary(cv_sl_mc) # Plot showing SL ensemble vs. each base learner library(ggplot2) plot(cv_sl_mc) + theme_bw() + ggtitle("CV SuperLearner Risk Estimates") ``` -------------------------------- ### Parallel Cross-Validation with mcSuperLearner Source: https://context7.com/ecpolley/superlearner/llms.txt Utilize mcSuperLearner for multicore parallel execution of the cross-validation step, recommended for Unix/macOS systems. Set the 'mc.cores' option to control the number of parallel workers. ```R library(SuperLearner) data(Boston, package = "MASS") set.seed(1) sl_lib <- c("SL.xgboost", "SL.randomForest", "SL.glmnet", "SL.ksvm", "SL.nnet", "SL.lm", "SL.mean") # mcSuperLearner uses parallel::mclapply internally (Unix/macOS) # Set mc.cores option to control number of parallel workers options(mc.cores = 4) sl_mc <- mcSuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = sl_lib, family = gaussian(), cvControl = list(V = 10) ) # Results are identical to SuperLearner(), just faster sl_mc$coef sl_mc$times$train # training time (proc.time diff) ``` -------------------------------- ### Create Random Forest Learners with Fixed ntree and mtry Grid Source: https://context7.com/ecpolley/superlearner/llms.txt Generates `SL.randomForest` learners with a fixed `ntree` parameter and a grid search over `mtry`. Ensure to remove created functions from the global environment after use. ```r library(SuperLearner) data(Boston, package = "MASS") set.seed(1) # --- Example 2: Random Forest with fixed ntree and grid over mtry --- rf_learners <- create.Learner( base_learner = "SL.randomForest", params = list(ntree = 1000), tune = list(mtry = c(2, 4, 6, 8)) ) sl_rf <- SuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = rf_learners$names, family = gaussian() ) # Clean up created functions from global environment when done rm(list = rf_learners$names) ``` -------------------------------- ### Plot SuperLearner Performance Source: https://github.com/ecpolley/superlearner/blob/master/README.md Visualizes the performance of individual algorithms and compares them to the SuperLearner ensemble. Uses ggplot2 theming. ```r # Plot performance of individual algorithms and compare to the ensemble. plot(result2) + theme_minimal() ``` -------------------------------- ### predict.SuperLearner() Source: https://context7.com/ecpolley/superlearner/llms.txt Generates ensemble and individual library algorithm predictions on new data. This function requires that `control$saveFitLibrary = TRUE` was used during the initial `SuperLearner()` fit. ```APIDOC ## predict.SuperLearner() ### Description Generate ensemble predictions and individual library algorithm predictions on new data. Requires that `control$saveFitLibrary = TRUE` (the default) was used when fitting the original SuperLearner. ### Method predict(object, newdata, onlySL = FALSE, ...) ### Parameters - **object** (SuperLearner object) - The fitted SuperLearner object. - **newdata** (data.frame) - The new data for which to generate predictions. - **onlySL** (logical) - If TRUE, only computes predictions from algorithms with non-zero ensemble weights, potentially improving efficiency. - **...** - Additional arguments passed to other methods. ### Request Example ```r library(SuperLearner) data(Boston, package = "MASS") set.seed(42) # Split into train/test train_idx <- sample(nrow(Boston), 400) train <- Boston[train_idx, ] test <- Boston[-train_idx, ] sl_fit <- SuperLearner( Y = train$medv, X = train[, -14], SL.library = c("SL.glmnet", "SL.randomForest", "SL.lm"), family = gaussian() ) # Predict on new data preds <- predict(sl_fit, newdata = test[, -14]) # preds$pred — ensemble predictions (length = nrow(test)) # preds$library.predict — matrix of per-algorithm predictions head(preds$pred) # Optionally skip algorithms with zero ensemble weight for efficiency preds_fast <- predict(sl_fit, newdata = test[, -14], onlySL = TRUE) # Evaluate performance (RMSE) rmse <- sqrt(mean((preds$pred - test$medv)^2)) cat("RMSE:", round(rmse, 3), "\n") ``` ### Response A list containing: - **pred**: A numeric vector of ensemble predictions for the `newdata`. - **library.predict**: A matrix where columns represent predictions from individual library algorithms for the `newdata`. ``` -------------------------------- ### Define Custom Metalearner for Simple Average Source: https://context7.com/ecpolley/superlearner/llms.txt Create a custom metalearner function, method.EqualWeight, that computes equal weights for base learners. This function can be passed to SuperLearner to control how predictions are combined. ```R method.EqualWeight <- function() { list( require = NULL, computeCoef = function(Z, Y, libraryNames, obsWeights, control, verbose, ...) { k <- ncol(Z) coef <- rep(1 / k, k) names(coef) <- libraryNames cvRisk <- apply(Z, 2, function(x) mean(obsWeights * (x - Y)^2)) list(cvRisk = cvRisk, coef = coef, optimizer = NULL) }, computePred = function(predY, coef, ...) { as.numeric(predY %*% coef) } ) } ``` ```R data(Boston, package = "MASS") set.seed(1) sl_eq <- SuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = c("SL.glmnet", "SL.randomForest", "SL.lm"), family = gaussian(), method = method.EqualWeight() ) sl_eq$coef ``` -------------------------------- ### Perform 5-fold Cross-Validation with SuperLearner Source: https://context7.com/ecpolley/superlearner/llms.txt Performs k-fold cross-validation for SuperLearner models. Use `parallel = "multicore"` for parallel execution. The risk estimates are based on Mean Squared Error by default for `gaussian()` families. ```r cv_sl <- CV.SuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = sl_lib, family = gaussian(), V = 5, parallel = "seq" # use "multicore" for parallel execution ) # Summary table of CV risk estimates with standard errors summary(cv_sl) # Risk is based on: Mean Squared Error # Algorithm Ave se Min Max # SL.predict 9.85 0.74 8.12 12.30 # SL.xgboost_All 10.12 0.81 8.50 12.90 # SL.randomForest 11.40 0.90 9.20 14.10 # ... # Plot CV risk with confidence intervals (requires ggplot2) library(ggplot2) plot(cv_sl) + theme_minimal() ``` -------------------------------- ### Fit SuperLearner Ensemble Source: https://context7.com/ecpolley/superlearner/llms.txt Fits a SuperLearner ensemble for regression tasks using a specified library of algorithms and cross-validation. Inspect the resulting ensemble weights and performance metrics. ```r library(SuperLearner) data(Boston, package = "MASS") set.seed(1) # Define the library of algorithms sl_lib <- c("SL.xgboost", "SL.randomForest", "SL.glmnet", "SL.nnet", "SL.ksvm", "SL.rpartPrune", "SL.lm", "SL.mean") # Fit the SuperLearner ensemble for regression (gaussian family is default) sl_fit <- SuperLearner( Y = Boston$medv, # numeric outcome vector X = Boston[, -14], # predictor data.frame (no missing values) SL.library = sl_lib, family = gaussian(), method = "method.NNLS", # default: non-negative least squares cvControl = list(V = 10), # 10-fold cross-validation verbose = FALSE ) # Inspect ensemble weights and per-algorithm CV risk print(sl_fit) # SuperLearner: # Algorithm Coef Risk # SL.xgboost_All 0.52 10.3 # SL.randomForest 0.31 11.8 # SL.glmnet_All 0.17 13.2 # ... # Access components directly sl_fit$coef # named vector of ensemble weights sl_fit$cvRisk # CV risk per algorithm sl_fit$SL.predict # ensemble predictions on training data sl_fit$library.predict # n x k matrix of per-algorithm predictions sl_fit$times$everything # total elapsed time (proc.time diff) ``` -------------------------------- ### Predict with SuperLearner Ensemble Source: https://context7.com/ecpolley/superlearner/llms.txt Generates predictions on new data using a fitted SuperLearner ensemble. Optionally, predictions can be made only using algorithms with non-zero ensemble weights for efficiency. ```r library(SuperLearner) data(Boston, package = "MASS") set.seed(42) # Split into train/test train_idx <- sample(nrow(Boston), 400) train <- Boston[train_idx, ] test <- Boston[-train_idx, ] sl_fit <- SuperLearner( Y = train$medv, X = train[, -14], SL.library = c("SL.glmnet", "SL.randomForest", "SL.lm"), family = gaussian() ) # Predict on new data preds <- predict(sl_fit, newdata = test[, -14]) # preds$pred — ensemble predictions (length = nrow(test)) # preds$library.predict — matrix of per-algorithm predictions head(preds$pred) # [1] 22.4 18.7 30.1 19.8 24.3 21.0 # Optionally skip algorithms with zero ensemble weight for efficiency preds_fast <- predict(sl_fit, newdata = test[, -14], onlySL = TRUE) # Evaluate performance (RMSE) rmse <- sqrt(mean((preds$pred - test$medv)^2)) cat("RMSE:", round(rmse, 3), "\n") ``` -------------------------------- ### Fit SuperLearner Ensemble Source: https://github.com/ecpolley/superlearner/blob/master/README.md Fits an ensemble of various machine learning algorithms including XGBoost, Random Forest, Lasso, Neural Net, SVM, BART, K-nearest neighbors, Decision Tree, OLS, and a simple mean predictor. Requires the MASS package for the Boston dataset. ```r data(Boston, package = "MASS") set.seed(1) sl_lib = c("SL.xgboost", "SL.randomForest", "SL.glmnet", "SL.nnet", "SL.ksvm", "SL.bartMachine", "SL.kernelKnn", "SL.rpartPrune", "SL.lm", "SL.mean") # Fit XGBoost, RF, Lasso, Neural Net, SVM, BART, K-nearest neighbors, Decision Tree, # OLS, and simple mean; create automatic ensemble. result = SuperLearner(Y = Boston$medv, X = Boston[, -14], SL.library = sl_lib) # Review performance of each algorithm and ensemble weights. result ``` -------------------------------- ### SuperLearner() Source: https://context7.com/ecpolley/superlearner/llms.txt Fits an ensemble of machine learning algorithms using V-fold cross-validation. It combines algorithms via non-negative least squares (NNLS) by default and returns an object containing ensemble coefficients and performance metrics. ```APIDOC ## SuperLearner() ### Description Fits an ensemble of machine learning algorithms using V-fold cross-validation. Algorithms in `SL.library` are trained on each CV fold and combined using non-negative least squares (NNLS) by default. Returns an object of class "SuperLearner" containing ensemble coefficients, per-algorithm CV risk, and fitted models. ### Method SuperLearner() ### Parameters - **Y** (numeric vector) - The outcome vector. - **X** (data.frame) - The predictor data. - **SL.library** (character vector) - A library of algorithms to include in the ensemble. - **family** (family object) - The distribution family for the outcome (e.g., `gaussian()`, `binomial()`). - **method** (character) - The method for combining algorithms (e.g., "method.NNLS"). - **cvControl** (list) - Control parameters for cross-validation (e.g., `list(V = 10)` for 10-fold CV). - **verbose** (logical) - Whether to print verbose output during fitting. ### Request Example ```r library(SuperLearner) data(Boston, package = "MASS") set.seed(1) # Define the library of algorithms sl_lib <- c("SL.xgboost", "SL.randomForest", "SL.glmnet", "SL.nnet", "SL.ksvm", "SL.rpartPrune", "SL.lm", "SL.mean") # Fit the SuperLearner ensemble for regression (gaussian family is default) sl_fit <- SuperLearner( Y = Boston$medv, X = Boston[, -14], SL.library = sl_lib, family = gaussian(), method = "method.NNLS", cvControl = list(V = 10), verbose = FALSE ) # Inspect ensemble weights and per-algorithm CV risk print(sl_fit) ``` ### Response An object of class `"SuperLearner"` with components: - **coef**: Named vector of ensemble weights. - **cvRisk**: CV risk per algorithm. - **SL.predict**: Ensemble predictions on training data. - **library.predict**: Matrix of per-algorithm predictions on training data. - **times**: Elapsed time information. ``` -------------------------------- ### CV.SuperLearner() Source: https://context7.com/ecpolley/superlearner/llms.txt Estimates the performance of the SuperLearner ensemble using an outer layer of V-fold cross-validation (nested CV). Each fold trains a full SuperLearner and evaluates it on the held-out data. ```APIDOC ## CV.SuperLearner() ### Description Estimate the performance of the SuperLearner ensemble itself using an outer layer of V-fold cross-validation (i.e., nested CV). Each fold trains a full SuperLearner and evaluates it on the held-out data. Returns a `"CV.SuperLearner"` object. ### Method CV.SuperLearner(Y, X, SL.library, cvControl = list(V = 10), ...) ### Parameters - **Y** (numeric vector) - The outcome vector. - **X** (data.frame) - The predictor data. - **SL.library** (character vector) - A library of algorithms to include in the ensemble. - **cvControl** (list) - Control parameters for the outer cross-validation (e.g., `list(V = 10)` for 10-fold CV). - **...** - Additional arguments passed to `SuperLearner()`. ### Request Example ```r library(SuperLearner) data(Boston, package = "MASS") set.seed(1) sl_lib <- c("SL.glmnet", "SL.randomForest", "SL.xgboost", "SL.lm", "SL.mean") # Example usage (fitting is shown, but output is not detailed in source) # cv_sl_fit <- CV.SuperLearner( # Y = Boston$medv, # X = Boston[, -14], # SL.library = sl_lib, # cvControl = list(V = 5) # ) ``` ### Response An object of class `"CV.SuperLearner"` containing performance estimates for the SuperLearner ensemble. ``` -------------------------------- ### Cross-Validate SuperLearner Performance Source: https://context7.com/ecpolley/superlearner/llms.txt Estimates the performance of the SuperLearner ensemble using nested cross-validation. Each outer fold trains a complete SuperLearner and evaluates it on held-out data. ```r library(SuperLearner) data(Boston, package = "MASS") set.seed(1) sl_lib <- c("SL.glmnet", "SL.randomForest", "SL.xgboost", "SL.lm", "SL.mean") ``` -------------------------------- ### Cross-Validated SuperLearner Ensemble Source: https://github.com/ecpolley/superlearner/blob/master/README.md Estimates the accuracy of the SuperLearner ensemble using external (nested) cross-validation. This process can be computationally intensive. ```r # Use external (aka nested) cross-validation to estimate ensemble accuracy. # This will take a while to run. result2 = CV.SuperLearner(Y = Boston$medv, X = Boston[, -14], SL.library = sl_lib) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.