0
$\begingroup$

I have learned the basic method of cross-validation, but I have a question. Before cross-validation, how to build a logistic regression model fist? I mean that should I use the complete data set to build logistic regression model(not split data to training set and validation set), and then use the complete data set for K Fold cross-validation?

For example: My data set is named mydata, and then use the complete data set to filter variables and build logistic regression model, finally, use the model and complete data set to perform K-fold cross-validation, is this process correct?

$\endgroup$
3
  • $\begingroup$ It sounds like you're confused re: what the main point of using cross validation is. I'd be happy to help but I think it would be a worthwhile exercise for you to think about why you need CV in the first place. $\endgroup$
    – Adrià Luz
    Sep 25, 2021 at 14:05
  • $\begingroup$ I'm a new in cross-validation, and I am also trying to read more articles and blogs about cross-validation, but I'm still don’t know how to get the final model with CV. Is there any R code for the whole process of obtaining the final model through cross-validation? Maybe I can further understand the principles of cross-validation in modeling regression models. $\endgroup$
    – dbcoffee
    Sep 25, 2021 at 15:38
  • $\begingroup$ Are you using cross validation to tune your model's hyperparameters too? Or only to understand how well it will generalise to unseen data? $\endgroup$
    – Adrià Luz
    Sep 25, 2021 at 15:57

1 Answer 1

2
$\begingroup$

Cross validation is intended to estimate the generalization error of the model building process you’re using.

You don’t build a model prior to doing cross validation. In each of the folds, you build a model doing everything you intend to do on the training data (including variable selection). Each model built on the K folds predicts on the held out part of the data to obtain an error or loss metric. The average of those error/loss metrics is an estimate of the error/loss metric for that model building process

$\endgroup$
3
  • $\begingroup$ Thank you for your explanation, but after reading more articles, I still don’t quite understand how to get the final model through cross-validation. $\endgroup$
    – dbcoffee
    Sep 25, 2021 at 15:43
  • $\begingroup$ @dbcoffee you don’t get the final model from cross validation. You get the final model by fitting your model to the training data. Cross validation is a means of estimating error on new data, not a means of fitting a model. $\endgroup$ Sep 25, 2021 at 15:55
  • $\begingroup$ I think I probably understand the purpose of cross-validation. The purpose of cross-validation is to evaluate the generalization ability of the model and not for the purpose to build model. Back to the question above, If I only have one data set mydata, can I use mydata to build a logistic regression model first, and then use mydata to perform K-fold cross-validation to evaluate the generalization ability of the model just created? If not, how can I build and verify the model with only one data set (small sample)? $\endgroup$
    – dbcoffee
    Sep 26, 2021 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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