Reputation: 58
I used cross validation to find optimal hyperparameters using the Caret package in R. This model is fit on the complete training data, but I want to train the final model on both the train and test data. How can I do this?
Upvotes: 0
Views: 525
Reputation: 46908
You can get the best parameter and fit it in as a single grid:
library(caret)
idx = sample(nrow(iris),100)
dat = iris
dat$Species = ifelse(atd$Species=="versicolor","v","o")
traindf = dat[idx,]
testdf = dat[idx,]
mdl = train(Species ~ .,data=traindf,method="gbm",
trControl=trainControl(method="cv"))
train_fit = train(Species ~ .,data=traindf,method="gbm",
trControl=trainControl(method="cv"),
tuneGrid = mdl$bestTune)
test_fit = train(Species ~ .,data=testdf,method="gbm",
trControl=trainControl(method="cv"),
tuneGrid = mdl$bestTune)
Since you did not provide the data or more information. this is the straightforward way. Otherwise you would call the method, for example in this case gbm()
and fit again.
Upvotes: 2