Skip to contents

Determine Weights for Density Estimators for SuperLearner

Usage

determine_weights_using_neg_log_loss(
  data,
  y_variable,
  obs_weights = NULL,
  bound_eps = 0.001
)

Arguments

data

A data.frame with columns corresponding to predicted densities from each learner and the true y_variable from held-out data

y_variable

A character indicating the outcome variable in the data.frame.

obs_weights

A vector of weights for each observation that dictate how prediction should be more targeted to higher weighted observations.

bound_eps

A numeric value used for truncating probability (densities) away from 0.

Value

A vector of weights to be used for each of the learners.

Examples

predicted_densities <- data.frame(
  lm = lnr_lm_density(mtcars, mpg ~ hp)(mtcars),
  earth = lnr_homoskedastic_density(mtcars, mpg ~ hp, mean_lnr = lnr_earth)(mtcars),
  rf = lnr_homoskedastic_density(mtcars, mpg ~ hp, mean_lnr = lnr_rf)(mtcars),
  rf2 = lnr_homoskedastic_density(mtcars, mpg ~ hp,
    mean_lnr = lnr_rf,
    mean_lnr_args = list(ntree = 20)
  )(mtcars),
  mpg = mtcars$mpg
)
determine_weights_using_neg_log_loss(predicted_densities, y_variable = "mpg")
#> [1] 7.651204e-243 2.786809e-103  9.138556e-18  1.000000e+00