3
$\begingroup$

Based on my understanding from google and other posts, like this What is cross-validation for? and What is cross-validation? . I understand that (k- fold) cross validation means spliting the data into ($k-1$) training and 1 testing set. In other words, it is used for finding the model accuracy.

So, is that mean if I do cross-validation, then I don't need to split my data into training and testing dataset? Also, say if I do (in r):

model = train(target~., data = data, method = "glmnet",
  trControl = trainControl("cv", number = 10),
  tuneLength = 10
)

this code will find me the best model in those 10 trials, and then when I do the prediction, I am using the best model?

$\endgroup$
3
$\begingroup$

Cross-validation is a special form ob splitting data into training and testing data, in which this splitting does not only occur once but a number $n$ of times.

Also, say if I do (in r)

There is a very powerfull package that can be loaded into R, called caret. caret delivers the very powerful function train that is used in your sample code. caret does indeed take a lot out of the work of finding the best set of parameters (out of a grid of possible combinations) for machine learning; including via cross validation. You will not have to split the data by hand but splitting will occur.

this code will find me the best model

it will find the best parameter combination from a given grid of parameter combinations by trying out. Before using a powerful tool like train you should understand its options well, also understand, how to influence which parameter grid is being tried out.

Fortunately caret comes with great explanations. Start here: https://topepo.github.io/caret/model-training-and-tuning.html or better start at the beginning of that book.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.