this is a R function for training ensemble models