I run the loop 200 times, during which I:
randomly divide my data set into training and test sets
corresponds to a neural network model with the R nnet() command on the training set
evaluate test suite performance
I keep each model in a list.
Now I want to use a combined model to create predictions outside the sample. I used the combine function for this purpose on randomForest objects. Is there a similar command command for nnet objects?
I canโt load the dataset, but below is the code I'm working with now. It works as it is, with the exception of the last line, where I am looking for a command to combine models.
n <- 200 nnet_preds <- matrix(NA, ncol = 1, nrow = n) nnet_predstp <- matrix(NA, ncol = 1, nrow = n) nnet_predstn <- matrix(NA, ncol = 1, nrow = n) nnet_predsfptp <- matrix(NA, ncol = 1, nrow = n) nnet_predsfntp <- matrix(NA, ncol = 1, nrow = n) NN_predictions <- matrix(NA, ncol = 1, nrow = 10) outcome_2010_NN <- testframe2[, "ytest"] nn_model <- vector("list", n) data<-testframe2[, c("sctownpop", "sctownhh", "scnum_tribes", "sctownmusl_percap", "scmuslim", "scprop_stranger", "sctownstrg_percap", "scprop_domgroup", "scexcom", "sctownexcm_percap", "sctownretn_percap", "scprop_under30", "scprop_male", "scedulevel", "scprop_noeduc", "scprop_anypeace", "scgroup_prtcptn", "scpubcontr", "scsafecommdum", "scciviccommdum", "scoll_action_add", "scngodependent", "scgovtdependent", "scpolicourtscorr", "screlmarry", "scmslmnolead", "sccrime_scale", "scviol_scale", "sclandconf_scale", "sctownnlnd_percap", "scnolandnofarm", "scfarmocc", "scunemployed", "scwealthindex", "scwealth_inequality", "scviol_experienced", "scviol_part", "scanylndtake", "scdisp_ref", "sfacilities", "sfreq_visits", "sctot_resources", "scmeanprice_above75", "scmosquesdum", "scmnrt_ldrshp", "scany_majorconf", "sstate_presence", "sremote", "scmobilec", "scradio_low")] data = cbind(outcome_2010_NN, data) sampleSplit = round(nrow(data)-(nrow(data)/5)) for(i in 1:n) { set.seed(06511+i) data_randomization <- data[sample(1:nrow(data), dim(data)[1], replace=FALSE), ] train <- data_randomization[1:sampleSplit, ] test <- data_randomization[(sampleSplit+1):nrow(data), ] nn_model[[i]] <- nnet(outcome_2010_NN ~ sctownpop + sctownhh+ scnum_tribes+ sctownmusl_percap+ scmuslim+ scprop_stranger+ sctownstrg_percap+ scprop_domgroup+ scexcom+ sctownexcm_percap+ sctownretn_percap+ scprop_under30 + scprop_male+ scedulevel+ scprop_noeduc+ scprop_anypeace+ scgroup_prtcptn+ scpubcontr+ scsafecommdum+ scciviccommdum+ scoll_action_add+ scngodependent+ scgovtdependent+ scpolicourtscorr+ screlmarry+ scmslmnolead+ sccrime_scale+ scviol_scale+ sclandconf_scale+ sctownnlnd_percap+ scnolandnofarm+ scfarmocc+ scunemployed+ scwealthindex+ scwealth_inequality+ scviol_experienced+ scviol_part+ scanylndtake+ scdisp_ref+ sfacilities+ sfreq_visits+ sctot_resources+ scmeanprice_above75+ scmosquesdum+ scmnrt_ldrshp+ scany_majorconf+ sstate_presence+ sremote+ scmobilec+ scradio_low, data=train, size = 3, decay = 0.1) nnet (outcome_2010_NN ~ sctownpop + sctownhh + scnum_tribes + sctownmusl_percap + scmuslim + scprop_stranger + sctownstrg_percap + scprop_domgroup + scexcom + sctownexcm_percap + sctownretn_percap + scprop_under30 + scprop_male + scedulevel + scprop_noeduc + scprop_anypeace + scgroup_prtcptn + scpubcontr + scsafecommdum + scciviccommdum + scoll_action_add + scngodependent + scgovtdependent + scpolicourtscorr + screlmarry + scmslmnolead + sccrime_scale + scviol_scale + sclandconf_scale + sctownnlnd_percap + scnolandnofarm + scfarmocc + scunemployed + scwealthindex + scwealth_inequality + scviol_experienced + n <- 200 nnet_preds <- matrix(NA, ncol = 1, nrow = n) nnet_predstp <- matrix(NA, ncol = 1, nrow = n) nnet_predstn <- matrix(NA, ncol = 1, nrow = n) nnet_predsfptp <- matrix(NA, ncol = 1, nrow = n) nnet_predsfntp <- matrix(NA, ncol = 1, nrow = n) NN_predictions <- matrix(NA, ncol = 1, nrow = 10) outcome_2010_NN <- testframe2[, "ytest"] nn_model <- vector("list", n) data<-testframe2[, c("sctownpop", "sctownhh", "scnum_tribes", "sctownmusl_percap", "scmuslim", "scprop_stranger", "sctownstrg_percap", "scprop_domgroup", "scexcom", "sctownexcm_percap", "sctownretn_percap", "scprop_under30", "scprop_male", "scedulevel", "scprop_noeduc", "scprop_anypeace", "scgroup_prtcptn", "scpubcontr", "scsafecommdum", "scciviccommdum", "scoll_action_add", "scngodependent", "scgovtdependent", "scpolicourtscorr", "screlmarry", "scmslmnolead", "sccrime_scale", "scviol_scale", "sclandconf_scale", "sctownnlnd_percap", "scnolandnofarm", "scfarmocc", "scunemployed", "scwealthindex", "scwealth_inequality", "scviol_experienced", "scviol_part", "scanylndtake", "scdisp_ref", "sfacilities", "sfreq_visits", "sctot_resources", "scmeanprice_above75", "scmosquesdum", "scmnrt_ldrshp", "scany_majorconf", "sstate_presence", "sremote", "scmobilec", "scradio_low")] data = cbind(outcome_2010_NN, data) sampleSplit = round(nrow(data)-(nrow(data)/5)) for(i in 1:n) { set.seed(06511+i) data_randomization <- data[sample(1:nrow(data), dim(data)[1], replace=FALSE), ] train <- data_randomization[1:sampleSplit, ] test <- data_randomization[(sampleSplit+1):nrow(data), ] nn_model[[i]] <- nnet(outcome_2010_NN ~ sctownpop + sctownhh+ scnum_tribes+ sctownmusl_percap+ scmuslim+ scprop_stranger+ sctownstrg_percap+ scprop_domgroup+ scexcom+ sctownexcm_percap+ sctownretn_percap+ scprop_under30 + scprop_male+ scedulevel+ scprop_noeduc+ scprop_anypeace+ scgroup_prtcptn+ scpubcontr+ scsafecommdum+ scciviccommdum+ scoll_action_add+ scngodependent+ scgovtdependent+ scpolicourtscorr+ screlmarry+ scmslmnolead+ sccrime_scale+ scviol_scale+ sclandconf_scale+ sctownnlnd_percap+ scnolandnofarm+ scfarmocc+ scunemployed+ scwealthindex+ scwealth_inequality+ scviol_experienced+ scviol_part+ scanylndtake+ scdisp_ref+ sfacilities+ sfreq_visits+ sctot_resources+ scmeanprice_above75+ scmosquesdum+ scmnrt_ldrshp+ scany_majorconf+ sstate_presence+ sremote+ scmobilec+ scradio_low, data=train, size = 3, decay = 0.1)