cobra: Cobra Meta Learner

View source: R/cobra.R

cobraR Documentation

Cobra Meta Learner

Description

The function cobra implements the COBRA (COmBined Regression Alternative), an aggregation method for combining predictions from multiple individual learners. This method aims to tune key parameters for achieving optimal predictions by averaging the target values of similar candidates in the training dataset's predictions. Only the training points that are sufficiently similar to the test point (based on the proximity threshold epsilon) are used for prediction. If no suitable training points are found, the function returns NA.

Usage

cobra(x, y, tune = "epsilon", k_folds = NULL, eps = NULL)

Arguments

x

data.frame
A training data, where rows are observations and columns are predictions from individual learners. Use NA for missing predictions.

y

vector
A vector containing the training targets. This can be a binary or two-level factor variable.

tune

character
A character value specifying the tuning mode:

  • "alpha_epsilon": Tunes both alpha (number of learners) and epsilon (proximity threshold) via cross-validation.

  • "epsilon": Tunes epsilon only via cross-validation.

  • "user": No tuning; the user provides an optimal epsilon. #' The default value is epsilon.

k_folds

integer
Number of folds for cross-validation when tune = "alpha_epsilon" or "epsilon". Default is 10.

eps

numeric
A numeric value for the proximity threshold, used only when tune = "user". Defaults to 0.1.

Value

An object of class cobra containing the training data, target values, and chosen parameters.

References

Biau, G., Fischer, A., Guedj, B., & Malley, J. D. (2014). COBRA: A combined regression strategy. The Journal of Multivariate Analysis 46:18-28

Examples

# Example usage
set.seed(123)
x_train <- data.frame(a = runif(10L), b = runif(10L))
y_train <- sample(0L:1L, size = 10L, replace = TRUE)

# Train the model with epsilon optimization
cobra_model <- cobra(x = x_train, y = y_train, tune = "epsilon", k_folds = 2)

# Make predictions on new data
set.seed(156)
x_new <- data.frame(a = runif(5L), b = runif(5L))
prediction <- predict(object = cobra_model, data = x_new)


fuseMLR documentation built on April 3, 2025, 8:49 p.m.