
Bagging over LCG-seeded bootstrap replicates (Geron Ch 6, morie.fn hmbag)
Source:R/geron_ml_native.R
morie_geron_bagging.RdBootstrap indices come from the exact-integer LCG, index m using seed
7919 m, so replicates are byte-identical across machines. Default weak learner is a least-squares 1-split stump.
Usage
morie_geron_bagging(
X,
y,
base_estimator = NULL,
n_estimators = 10,
seed = 0,
task = "auto"
)Value
List with predict, train_pred, train_mse, oob_pred,
oob_mse, oob_coverage, member_preds, task.
Examples
V <- c(1, 2, 3, 4, 5, 6, 7, 8)
morie_geron_bagging(V, V)
#> $predict
#> function (Xnew)
#> {
#> Bm <- if (is.matrix(Xnew))
#> Xnew
#> else matrix(as.numeric(Xnew), ncol = ncol(A))
#> .morie_gr_need(ncol(Bm) == ncol(A), "predict: feature count mismatch")
#> P <- do.call(rbind, lapply(models, function(f) as.numeric(f(Bm))))
#> aggregate(P)
#> }
#> <environment: 0x56216a5497c0>
#>
#> $train_pred
#> [1] 2.495000 2.495000 2.495000 3.353095 5.631429 6.271429 6.271429 6.271429
#>
#> $train_mse
#> [1] 0.893089
#>
#> $oob_pred
#> [1] 3.600000 2.550000 2.000000 3.241071 5.526984 NA 5.766667 6.082993
#>
#> $oob_mse
#> [1] 2.01603
#>
#> $oob_coverage
#> [1] 0.875
#>
#> $estimators
#> $estimators[[1]]
#> function (Anew)
#> {
#> Bm <- if (is.matrix(Anew))
#> Anew
#> else matrix(as.numeric(Anew), ncol = ncol(A))
#> ifelse(Bm[, j] <= thr, lp, rp)
#> }
#> <environment: 0x56216a514860>
#>
#> $estimators[[2]]
#> function (Anew)
#> {
#> Bm <- if (is.matrix(Anew))
#> Anew
#> else matrix(as.numeric(Anew), ncol = ncol(A))
#> ifelse(Bm[, j] <= thr, lp, rp)
#> }
#> <bytecode: 0x56215cd56b80>
#> <environment: 0x562151ee2ce8>
#>
#> $estimators[[3]]
#> function (Anew)
#> {
#> Bm <- if (is.matrix(Anew))
#> Anew
#> else matrix(as.numeric(Anew), ncol = ncol(A))
#> ifelse(Bm[, j] <= thr, lp, rp)
#> }
#> <bytecode: 0x56215cd56b80>
#> <environment: 0x56215b21cb00>
#>
#> $estimators[[4]]
#> function (Anew)
#> {
#> Bm <- if (is.matrix(Anew))
#> Anew
#> else matrix(as.numeric(Anew), ncol = ncol(A))
#> ifelse(Bm[, j] <= thr, lp, rp)
#> }
#> <bytecode: 0x56215cd56b80>
#> <environment: 0x56215b77e728>
#>
#> $estimators[[5]]
#> function (Anew)
#> {
#> Bm <- if (is.matrix(Anew))
#> Anew
#> else matrix(as.numeric(Anew), ncol = ncol(A))
#> ifelse(Bm[, j] <= thr, lp, rp)
#> }
#> <bytecode: 0x56215cd56b80>
#> <environment: 0x5621536c75e8>
#>
#> $estimators[[6]]
#> function (Anew)
#> {
#> Bm <- if (is.matrix(Anew))
#> Anew
#> else matrix(as.numeric(Anew), ncol = ncol(A))
#> ifelse(Bm[, j] <= thr, lp, rp)
#> }
#> <bytecode: 0x56215cd56b80>
#> <environment: 0x5621566e4d40>
#>
#> $estimators[[7]]
#> function (Anew)
#> {
#> Bm <- if (is.matrix(Anew))
#> Anew
#> else matrix(as.numeric(Anew), ncol = ncol(A))
#> ifelse(Bm[, j] <= thr, lp, rp)
#> }
#> <bytecode: 0x56215cd56b80>
#> <environment: 0x562161deeab8>
#>
#> $estimators[[8]]
#> function (Anew)
#> {
#> Bm <- if (is.matrix(Anew))
#> Anew
#> else matrix(as.numeric(Anew), ncol = ncol(A))
#> ifelse(Bm[, j] <= thr, lp, rp)
#> }
#> <bytecode: 0x56215cd56b80>
#> <environment: 0x562164593ed0>
#>
#> $estimators[[9]]
#> function (Anew)
#> {
#> Bm <- if (is.matrix(Anew))
#> Anew
#> else matrix(as.numeric(Anew), ncol = ncol(A))
#> ifelse(Bm[, j] <= thr, lp, rp)
#> }
#> <bytecode: 0x56215cd56b80>
#> <environment: 0x5621587b2e28>
#>
#> $estimators[[10]]
#> function (Anew)
#> {
#> Bm <- if (is.matrix(Anew))
#> Anew
#> else matrix(as.numeric(Anew), ncol = ncol(A))
#> ifelse(Bm[, j] <= thr, lp, rp)
#> }
#> <bytecode: 0x56215cd56b80>
#> <environment: 0x562153837650>
#>
#>
#> $member_preds
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,] 3.000000 3.000000 3.000000 3.000000 6.000000 6.000000 6.000000 6.000000
#> [2,] 2.000000 2.000000 2.000000 2.000000 6.000000 6.000000 6.000000 6.000000
#> [3,] 2.000000 2.000000 2.000000 2.000000 7.200000 7.200000 7.200000 7.200000
#> [4,] 3.000000 3.000000 3.000000 3.000000 6.333333 6.333333 6.333333 6.333333
#> [5,] 2.500000 2.500000 2.500000 2.500000 6.000000 6.000000 6.000000 6.000000
#> [6,] 2.250000 2.250000 2.250000 2.250000 6.000000 6.000000 6.000000 6.000000
#> [7,] 2.666667 2.666667 2.666667 2.666667 2.666667 6.600000 6.600000 6.600000
#> [8,] 2.333333 2.333333 2.333333 5.200000 5.200000 5.200000 5.200000 5.200000
#> [9,] 4.200000 4.200000 4.200000 4.200000 4.200000 6.666667 6.666667 6.666667
#> [10,] 1.000000 1.000000 1.000000 6.714286 6.714286 6.714286 6.714286 6.714286
#>
#> $task
#> [1] "regression"
#>
#> $estimate
#> [1] 0.893089
#>
#> $n
#> [1] 8
#>
#> $method
#> [1] "Bagging over LCG-seeded bootstrap replicates"
#>