From f30672bf4509d3f0c1f587557526831126d77956 Mon Sep 17 00:00:00 2001 From: Tim Lucas Date: Mon, 25 May 2015 11:29:22 +0100 Subject: [PATCH] Fix incorrect sampling in bagged avNNet. avNNet with bag = TRUE currently samples without replacement. This therefore just reorders the rows. avNNet now samples WITH replacement therefore giving proper bagging. --- pkg/caret/R/avNNet.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/caret/R/avNNet.R b/pkg/caret/R/avNNet.R index 29466ed29..c06d0c304 100644 --- a/pkg/caret/R/avNNet.R +++ b/pkg/caret/R/avNNet.R @@ -73,7 +73,7 @@ avNNet.default <- function(x, y, repeats = 5, bag = FALSE, allowParallel = TRUE, { if(theDots$trace) cat("\nFitting Repeat", i, "\n\n") } else cat("Fitting Repeat", i, "\n\n") - if(bag) ind <- sample(1:nrow(x)) + if(bag) ind <- sample(1:nrow(x), replace = TRUE) thisMod <- if(is.null(classLev)) nnet::nnet(x[ind,,drop = FALSE], y[ind], ...) else nnet::nnet(x[ind,,drop = FALSE], y[ind,], ...) thisMod$lev <- classLev thisMod