Skip to contents

Retrieve the out-of-fold predictions corresponding to the best hyperparameter setting of a trained ensemble model. These predictions come from the resampling process (not the final refit) and can optionally be aggregated across resamples to produce a single prediction per training instance.

The base model predictions returned here are the training data for the ensemble; depending on model setup, these may be true out-of-fold predictions or simply fitted values. For classification models, the predictions always exclude the first class index.

Usage

# S3 method for class 'caret_stack'
oof_predictions(
  object,
  drop_redundant_class = TRUE,
  aggregate_resamples = TRUE,
  ...
)

Arguments

object

A caret_stack object

drop_redundant_class

A boolean controlling whether to exclude the first class level from prediction output. Default is TRUE.

aggregate_resamples

Logical, whether to aggregate resamples across folds. Default is TRUE.

...

Not used. Included for S3 compatibility.

Value

A data.table::data.table of OOF predictions

Examples

# Load pre-trained example caret_stack object
data(heart_failure_stack)

oof_predictions(heart_failure_stack)
#>          cells     holter       mrna     proteins   ensemble
#>          <num>      <num>      <num>        <num>      <num>
#>  1: 0.39487649 0.36909270 0.48528211 9.997811e-01 0.89049581
#>  2: 0.30042999 0.19092831 0.25769494 9.373699e-02 0.14543981
#>  3: 0.30951676 0.19776753 0.22497670 9.997515e-01 0.50525923
#>  4: 0.16856438 0.25586004 0.38829387 6.776068e-01 0.79606632
#>  5: 0.41325201 0.26108068 0.69638737 2.019989e-03 0.42305109
#>  6: 0.27731047 0.32077126 0.11945148 2.088767e-01 0.26910608
#>  7: 0.22868693 0.72770916 0.16006647 5.968584e-02 0.52116695
#>  8: 0.19812130 0.22315924 0.29885868 7.371038e-01 0.48398037
#>  9: 0.28245069 0.20305767 0.43981899 9.565369e-01 0.70439444
#> 10: 0.32602141 0.26537554 0.37696868 1.859125e-01 0.40203526
#> 11: 0.37483007 0.33358529 0.33333452 1.326082e-01 0.48682900
#> 12: 0.08630381 0.23597303 0.05027060 7.750342e-01 0.21107234
#> 13: 0.23705848 0.51748407 0.16169914 3.635292e-01 0.47502294
#> 14: 0.24890462 0.24752704 0.31577410 2.528748e-01 0.37240642
#> 15: 0.16485817 0.19310453 0.03896005 2.168373e-05 0.05538687
#> 16: 0.29836034 0.12731196 0.42092830 2.089819e-04 0.18375486
#> 17: 0.25248249 0.13824433 0.37510932 1.357990e-04 0.13695471
#> 18: 0.22111569 0.15846676 0.15097042 2.080887e-03 0.08897402
#> 19: 0.11506052 0.20298222 0.03965684 3.071741e-05 0.04949669
#> 20: 0.16720343 0.03408682 0.10517658 6.491938e-07 0.03082011
#> 21: 0.34169763 0.17087990 0.37915054 1.102010e-04 0.19616224
#> 22: 0.28499000 0.09697545 0.15869489 1.040837e-02 0.05367200
#> 23: 0.28998987 0.10841931 0.14548990 3.764977e-02 0.05621898
#> 24: 0.17026367 0.21782593 0.15414731 2.325022e-02 0.10961522
#> 25: 0.26097078 0.16607275 0.21527392 7.759198e-03 0.09326425
#> 26: 0.11557337 0.25547405 0.06512819 1.321670e-03 0.06536842
#> 27: 0.16806976 0.18684416 0.14001222 2.881488e-02 0.10548584
#> 28: 0.16140874 0.18343853 0.07281529 2.992745e-05 0.08280784
#> 29: 0.50363587 0.23432261 0.37152920 4.614976e-02 0.48542277
#> 30: 0.19335680 0.12323529 0.16026750 9.997972e-01 0.71496728
#> 31: 0.17046073 0.34741307 0.02591532 6.183194e-04 0.09997662
#> 32: 0.20395259 0.37475152 0.12137290 8.519739e-07 0.18497521
#> 33: 0.13475327 0.10556385 0.19182175 6.580083e-02 0.07222694
#> 34: 0.15205573 0.20320057 0.19483368 1.028951e-05 0.08256610
#> 35: 0.14307066 0.27616614 0.08411645 3.921382e-02 0.14456723
#> 36: 0.15406917 0.19031075 0.08721875 5.018993e-04 0.07522969
#> 37: 0.21878420 0.25251581 0.13351247 1.677715e-01 0.15873781
#> 38: 0.28762801 0.18878866 0.48419982 3.165184e-02 0.29317298
#> 39: 0.15848359 0.14055961 0.23861337 1.354355e-01 0.11768005
#> 40: 0.24134243 0.41930328 0.07057693 2.875275e-01 0.39077821
#> 41: 0.15603955 0.26941514 0.30355477 4.717852e-05 0.20049345
#> 42: 0.20344174 0.08548813 0.08988793 3.211487e-04 0.05225411
#> 43: 0.17211102 0.22394581 0.02238737 2.896243e-03 0.06398713
#> 44: 0.33876761 0.28533890 0.24602523 2.438060e-01 0.38256549
#> 45: 0.12614383 0.28878973 0.10738733 9.614251e-01 0.79287029
#> 46: 0.19607071 0.28419276 0.25867224 2.755540e-02 0.19694293
#> 47: 0.21257159 0.10444129 0.05393685 6.689628e-03 0.05030544
#> 48: 0.07923487 0.13012582 0.04952718 4.846500e-05 0.05073918
#> 49: 0.14327767 0.25349360 0.17677482 1.888111e-02 0.15426693
#> 50: 0.16109377 0.23186888 0.07240264 8.267249e-02 0.09747523
#> 51: 0.26002939 0.14337773 0.51303076 3.782414e-09 0.25217749
#> 52: 0.14196009 0.14765268 0.14732178 9.418949e-05 0.07843359
#> 53: 0.31849286 0.11478657 0.35674453 1.960297e-05 0.13486938
#> 54: 0.21928963 0.24589906 0.20535335 1.495299e-03 0.15344866
#> 55: 0.15713077 0.23479474 0.16622478 1.901394e-01 0.19437707
#> 56: 0.16761851 0.23202842 0.13296251 2.630405e-03 0.10343033
#> 57: 0.23673749 0.08269332 0.15435143 4.290682e-04 0.05176041
#> 58: 0.14136814 0.08577594 0.06301069 5.692005e-06 0.03607329
#>          cells     holter       mrna     proteins   ensemble
#>          <num>      <num>      <num>        <num>      <num>