Error in Training Multiple Models using caret package

Viewed 2679

I am facing a very confusing problem while using the caret package in R. For a comparison, I am training multiple models. After a few calls to train, this error message begins to show for which ever train call / train model I use:-

Error in UseMethod("train") : no applicable method for 'train' applied to an object of class "formula"

Once this error appears, no other model is trained but the above error appears instead.

When I restart R and load the caret package again, the same models for which this error appeared, get trained easily.

I am confused as to what seems to be the issue here?

I have made a function for the 5 training models I try to create:-

test = function(){

a = train(demand ~ temp, oldData, 'lm')
print("Done A")

b = train(demand ~ temp, oldData, 'rf', ntree = 10)
print("Done B")

c = train(demand ~ temp, data = oldData, method = "gbm", 
        trControl = objControl, tuneGrid = gbmGrid, verbose = F)
print("Done C")

d = train(demand ~ temp, oldData, 'mlp')
print("Done D")

e = train(demand ~ temp, oldData, 'monmlp')
print("Done E")
}

P.S: Although, I have trained all these models successfully, I am trying to create an ensemble function for which I intend to run all these calls together.

1 Answers

I found out what the problem is:-

The only model that was making trouble the "mlp" model. When we call train to use the "mlp" method, caret attaches 2 packages which are "RSNNS" and "Rcpp". My guess is that these packages depend on the information we provide using the train function. Once they are attached, that information is retained which causes the *above mentioned error after which no other model is able to be trained. If we detach both these packages before making another call to train, the models are trained successfully.

Related