Retrieve the out-of-fold predictions corresponding to the best hyperparameter setting of the trained caret models. 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.
Usage
# S3 method for class 'caret_list'
oof_predictions(
object,
drop_redundant_class = TRUE,
aggregate_resamples = TRUE,
intersection_only = TRUE,
...
)Arguments
- object
A
caret_listobject- drop_redundant_class
Logical, 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.- intersection_only
Logical, whether to trim down the out-of-fold predictions to only the intersection of samples that are present across all models in the list (i.e., the intersection of training indices used during resampling). Default is
TRUE.- ...
Not used. Included for S3 compatibility.
Value
A data.table::data.table of out-of-fold predictions, with samples as rows and predictions as columns.
Examples
# Load pre-trained example caret_stack object
data(heart_failure_stack)
# Extract the caret_list object from the caret_stack
base_models <- heart_failure_stack$caret_list
oof_predictions(base_models)
#> cells holter mrna proteins
#> <num> <num> <num> <num>
#> 1: 0.39487649 0.36909270 0.48528211 9.997811e-01
#> 2: 0.30042999 0.19092831 0.25769494 9.373699e-02
#> 3: 0.30951676 0.19776753 0.22497670 9.997515e-01
#> 4: 0.16856438 0.25586004 0.38829387 6.776068e-01
#> 5: 0.41325201 0.26108068 0.69638737 2.019989e-03
#> 6: 0.27731047 0.32077126 0.11945148 2.088767e-01
#> 7: 0.22868693 0.72770916 0.16006647 5.968584e-02
#> 8: 0.19812130 0.22315924 0.29885868 7.371038e-01
#> 9: 0.28245069 0.20305767 0.43981899 9.565369e-01
#> 10: 0.32602141 0.26537554 0.37696868 1.859125e-01
#> 11: 0.37483007 0.33358529 0.33333452 1.326082e-01
#> 12: 0.08630381 0.23597303 0.05027060 7.750342e-01
#> 13: 0.23705848 0.51748407 0.16169914 3.635292e-01
#> 14: 0.24890462 0.24752704 0.31577410 2.528748e-01
#> 15: 0.16485817 0.19310453 0.03896005 2.168373e-05
#> 16: 0.29836034 0.12731196 0.42092830 2.089819e-04
#> 17: 0.25248249 0.13824433 0.37510932 1.357990e-04
#> 18: 0.22111569 0.15846676 0.15097042 2.080887e-03
#> 19: 0.11506052 0.20298222 0.03965684 3.071741e-05
#> 20: 0.16720343 0.03408682 0.10517658 6.491938e-07
#> 21: 0.34169763 0.17087990 0.37915054 1.102010e-04
#> 22: 0.28499000 0.09697545 0.15869489 1.040837e-02
#> 23: 0.28998987 0.10841931 0.14548990 3.764977e-02
#> 24: 0.17026367 0.21782593 0.15414731 2.325022e-02
#> 25: 0.26097078 0.16607275 0.21527392 7.759198e-03
#> 26: 0.11557337 0.25547405 0.06512819 1.321670e-03
#> 27: 0.16806976 0.18684416 0.14001222 2.881488e-02
#> 28: 0.16140874 0.18343853 0.07281529 2.992745e-05
#> 29: 0.50363587 0.23432261 0.37152920 4.614976e-02
#> 30: 0.19335680 0.12323529 0.16026750 9.997972e-01
#> 31: 0.17046073 0.34741307 0.02591532 6.183194e-04
#> 32: 0.20395259 0.37475152 0.12137290 8.519739e-07
#> 33: 0.13475327 0.10556385 0.19182175 6.580083e-02
#> 34: 0.15205573 0.20320057 0.19483368 1.028951e-05
#> 35: 0.14307066 0.27616614 0.08411645 3.921382e-02
#> 36: 0.15406917 0.19031075 0.08721875 5.018993e-04
#> 37: 0.21878420 0.25251581 0.13351247 1.677715e-01
#> 38: 0.28762801 0.18878866 0.48419982 3.165184e-02
#> 39: 0.15848359 0.14055961 0.23861337 1.354355e-01
#> 40: 0.24134243 0.41930328 0.07057693 2.875275e-01
#> 41: 0.15603955 0.26941514 0.30355477 4.717852e-05
#> 42: 0.20344174 0.08548813 0.08988793 3.211487e-04
#> 43: 0.17211102 0.22394581 0.02238737 2.896243e-03
#> 44: 0.33876761 0.28533890 0.24602523 2.438060e-01
#> 45: 0.12614383 0.28878973 0.10738733 9.614251e-01
#> 46: 0.19607071 0.28419276 0.25867224 2.755540e-02
#> 47: 0.21257159 0.10444129 0.05393685 6.689628e-03
#> 48: 0.07923487 0.13012582 0.04952718 4.846500e-05
#> 49: 0.14327767 0.25349360 0.17677482 1.888111e-02
#> 50: 0.16109377 0.23186888 0.07240264 8.267249e-02
#> 51: 0.26002939 0.14337773 0.51303076 3.782414e-09
#> 52: 0.14196009 0.14765268 0.14732178 9.418949e-05
#> 53: 0.31849286 0.11478657 0.35674453 1.960297e-05
#> 54: 0.21928963 0.24589906 0.20535335 1.495299e-03
#> 55: 0.15713077 0.23479474 0.16622478 1.901394e-01
#> 56: 0.16761851 0.23202842 0.13296251 2.630405e-03
#> 57: 0.23673749 0.08269332 0.15435143 4.290682e-04
#> 58: 0.14136814 0.08577594 0.06301069 5.692005e-06
#> cells holter mrna proteins
#> <num> <num> <num> <num>