Skip to contents

Summarises the model inputs (outcome, outcome type, number of observations and cross-validation folds) and outputs (ensemble weights), plus any errors captured during training.

Combines the ensemble weights with each candidate learner's cross-validated held-out loss, using the loss appropriate to the model's outcome_type (mean squared error for continuous outcomes; negative log loss for binary, multiclass, and density outcomes).

Following the convention of coef.SuperLearner in the SuperLearner package, the "coefficients" of a super learner are the meta-learned ensemble weights on the candidate learners.

Returns the ensemble's cross-validated predictions on the held-out folds: each value is the learner-weighted prediction for an observation, produced by learners trained without that observation. These are honest (out-of-fold) rather than in-sample fitted values.

Observed outcomes minus the cross-validated ensemble predictions of fitted.nadir_sl_model. I.e., honest out-of-fold residuals. See that function's documentation for the row-ordering convention.

Returns the regression formula shared by all learners when a single formula was used, and otherwise the named list of per-learner formulas.

If the model was fit with train_on_whole_dataset = FALSE, no whole-dataset learner fits exist and this method errors with a message directing users to the out-of-fold prediction interfaces ($oof_predictions, $oof_predict(), $oof_predict_modified(), $oof_predict_fold()).

Usage

# S3 method for class 'nadir_sl_model'
print(x, digits = 3, ...)

# S3 method for class 'nadir_sl_model'
summary(object, ...)

# S3 method for class 'nadir_sl_model'
coef(object, ...)

# S3 method for class 'nadir_sl_model'
fitted(object, ...)

# S3 method for class 'nadir_sl_model'
residuals(object, ...)

# S3 method for class 'nadir_sl_model'
formula(x, ...)

# S3 method for class 'nadir_sl_model'
nobs(object, ...)

# S3 method for class 'nadir_sl_model'
predict(object, newdata, ...)

Arguments

x

An object of class nadir_sl_model.

digits

Number of digits for the printed weights.

...

Ellipses, solely provided so that the predict.nadir_sl_model method is compatible with the generic predict, which takes ellipses as an argument.

object

An object of class inheriting from nadir_sl_model.

newdata

A tabular data structure (data.frame or matrix) of predictor variables.

Value

x, invisibly.

An object of class summary.nadir_sl_model: a list with a $comparison data.frame (one row per learner: weight and held-out loss, best first) plus $y_variable, $outcome_type, $n_obs, and $n_folds.

A named numeric vector of ensemble weights summing to 1.

A numeric vector of cross-validated ensemble predictions (or, for density/multiclass outcomes, ensemble mixture densities or probabilities of the observed outcomes).

A numeric vector of out-of-fold residuals. Errors for outcome_type = 'density' or 'multiclass', where held-out predictions are not point predictions.

A formula if all learners share one; otherwise a named list of formulas, one per learner.

Integer number of rows of the (complete-case-filtered) training data.

a numeric vector of predicted values

Details

Values are returned in cross-validation fold order, matching the rows of $holdout_predictions (which contains the corresponding observed outcomes), not in the row order of the originally supplied data. For out-of-fold predictions in original row order, use crossfit_super_learner()$oof_predictions.

Examples

sl_fit <- super_learner(mtcars, mpg ~ hp,
  learners = list(lnr_mean, lnr_lm)
)
predict(sl_fit, newdata = mtcars)
#>           Mazda RX4       Mazda RX4 Wag          Datsun 710      Hornet 4 Drive 
#>           22.261329           22.261329           23.267174           22.261329 
#>   Hornet Sportabout             Valiant          Duster 360           Merc 240D 
#>           18.415448           22.557166           14.273731           25.101363 
#>            Merc 230            Merc 280           Merc 280C          Merc 450SE 
#>           23.148839           21.492153           21.492153           18.119611 
#>          Merc 450SL         Merc 450SLC  Cadillac Fleetwood Lincoln Continental 
#>           18.119611           18.119611           16.640427           16.048753 
#>   Chrysler Imperial            Fiat 128         Honda Civic      Toyota Corolla 
#>           15.161242           24.864694           25.693037           24.923861 
#>       Toyota Corona    Dodge Challenger         AMC Javelin          Camaro Z28 
#>           23.030505           19.894633           19.894633           14.273731 
#>    Pontiac Firebird           Fiat X1-9       Porsche 914-2        Lotus Europa 
#>           18.415448           24.864694           23.385509           22.083826 
#>      Ford Pantera L        Ferrari Dino       Maserati Bora          Volvo 142E 
#>           13.149551           18.415448            8.948666           22.320496