Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
KnowledgeHut upGradKnowledgeHut upGradBackend Development Bootcamp
  • Self-Paced
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

Cross Validation in Machine Learning: 4 Types of Cross Validation

Updated on 22 September, 2022

10.34K+ views
7 min read

Introduction

Model Development is a crucial step in a Data Science Project Life Cycle where we will try to train our data set with different types of Machine Learning models either of Supervised or Unsupervised Algorithms based on the Business Problem.

As we are aware that we have a lot of models that can be used to solve a business problem we need to assure that whatever model we select at the end of this phase should be performing well on the unseen data. So, we cannot just go with the evaluation metrics in order to select our best performing model.

We need something more apart from the metric which can help us to decide on our final Machine Learning model which we can deploy to production.

The process of determining whether the mathematical results calculating relationships between variables are acceptable as descriptions of the data is known as Validation. Usually, an error estimation for the model is made after training the model on the train data set, better known as the evaluation of residuals.

In this process, we measure the Training Error by calculating the difference between predicted response and original response. But this metric cannot be trusted because it works well only with the training data. It’s possible that the model is Underfitting or Overfitting the data.

Enrol for the Machine Learning Course from the World’s top Universities. Earn Masters, Executive PGP, or Advanced Certificate Programs to fast-track your career.

So, the problem with this evaluation technique or any other evaluation metric is that it does not give an indication of how well the model will perform to an unseen data set. The technique that helps to know this about our model is known as Cross-Validation.

FYI: Free nlp online course!

In this article, we will get to know more about the different types of cross-validation techniques, pros, and cons of each technique. Let’s start with the definition of Cross-Validation.

Cross-Validation Techniques in Machine Learning

Cross-Validation is a resampling technique that helps to make our model sure about its efficiency and accuracy on the unseen data. It is a method for evaluating Machine Learning models by training several other Machine learning models on subsets of the available input data set and evaluating them on the subset of the data set.

We have different types of Cross-Validation techniques but let’s see the basic functionality of Cross-Validation: The first step is to divide the cleaned data set into K partitions of equal size.

  1. Then we need to treat the Fold-1 as a test fold while the other K-1 as train folds and compute the score of the test-fold.
  2. We need to repeat step 2 for all folds taking another fold as a test while remaining as a train.
  3. Last step would be to take the average of scores of all the folds.

Read: Machine Learning Projects For Beginners

Types of Cross-Validation techniques in Machine Learning

1. Holdout Method

This technique works on removing a part of the training data set and sending that to a model that was trained on the rest of the data set to get the predictions. We then calculate the error estimation which tells how our model is doing on unseen data sets. This is known as the Holdout Method.

Pros

  1. This Method is Fully independent of data.
  2. This Method only needs to be run once so has lower computational costs.

Cons

  1. The Performance is subject to higher variance given the smaller size of the data.

2. K-Fold Cross-Validation

In a Data-Driven World, there is never enough data to train your model, on top of that removing a part of it for validation poses a greater problem of Underfitting and we risk losing important patterns and trends in our data set, which in turn increases Bias. So ideally, we require a method that provides ample amounts of data for training the model and leaves ample amounts of data for validation sets.

In K-Fold cross-validation, the data is divided into k subsets or we can take it as a holdout method repeated k times, such that each time, one of the k subsets is used as the validation set and the other k-1 subsets as the training set. The error is averaged over all k trials to get the total efficiency of our model.

We can see that each data point will be in a validation set exactly once and will be in a training set k-1 time. This helps us reduce bias as we are using most of the data for fitting and reduces variance as most of the data is also being used in the validation set.

Pros

  1. This will help to overcome the problem of computational power.
  2. Models may not be affected much if an outlier is present in data.
  3. It helps us overcome the problem of variability.

Cons

  1. Imbalanced data sets will impact our model.

3. Stratified K-Fold Cross-Validation

K Fold Cross Validation technique will not work as expected for an Imbalanced Data set. When we have an imbalanced data set, we need a slight change to the K Fold cross validation technique, such that each fold contains approximately the same strata of samples of each output class as the complete. This variation of using a stratum in K Fold Cross Validation is known as Stratified K Fold Cross Validation.

Pros

  1. It can improve different models using hyper-parameter tuning.
  2. Helps us compare models.
  3. It helps in reducing both Bias and Variance.

Also Read: Career in Machine Learning

 4. Leave-P-Out Cross-Validation

In this approach we leave p data points out of training data out of a total n data points, then n-p samples are used to train the model and p points are used as the validation set. This is repeated for all combinations, and then the error is averaged.

Pros

  1. It has Zero randomness
  2. The Bias will be lower

Cons

  1. This method is exhaustive and computationally infeasible.

What are different cross validation techniques used for regression problems?

Curious about What are different cross validation techniques used for regression problems? 

Cross Validation is an essential tool for assessing your model’s classification accuracy. Logistic Regression, Random Forest, and SVM carry their own advantages and disadvantages to the models. Here is where cross validation comes in.

When you cross validate, you take a variety of test and training data, average it, and then assign a score to your model. In practice, we typically fit Logistic Regression, Random Forest, and SVM to each model, but what if the scores for each model are similar? A cross validation technique in machine learning can notify you which among your models is the most accurate. There are various cross validation methods, but we will focus on three today: Validation, the “leave one out” method, and K-Fold. To comprehend the importance of cross validation and when you should use which method, we must first understand the models and their respective drawbacks.

Logistic regression

This is a binary classification model. It is commonly used when there are only two classes, such as in medical identification. You either have cancer, or you don’t, and you either have or don’t have Congestive Heart Failure. This model has the advantage of being a simple regression that works well for what it does, which is again a binomial classifier. This model, however, is susceptible to overfitting. Overfitting occurs when a model is trained and adapts to all of its data points, including outliers. This means that the model has received training so well that the anticipated output does not match the model’s goals.

Random Forest

Random Forest’s major benefit is its ability to handle massive amounts of data with thousands of features. It resamples the data during its training model. This is called bootstrapping. To recap, Bootstrapping is when you utilize data for sampling and then return the data to the original data set for reuse. Also, keep in mind that only one-third of the data in Random Forest is used for testing. These are known as Out of Bag samples (OOB), and you should base your model on the Out of Bag Error. Random Forest, like Logistic Regression, is susceptible to Overfitting if your set of data is disruptive.

Support Vector Machines (SVM)

These are useful when you need to fit a reasonably precise model to the data. It performs effectively when the number of features outnumbers the number of actual samples (a data set with 1000 columns and 800 rows). This model is also useful when there are a lot of features (here, “features” are called “dimensions”). It also works well when the class separation is accurate and leaves no room for error. It is also less susceptible to overfitting. Its disadvantage is that it does not work well with large data sets. This takes a lot of time to train. The final model is also difficult to comprehend and interpret.

Below are the three main classifiers. But bear in mind that once you fit and train all three models, you must check with a cross validation technique in machine learning.

Simple Validation

You will test on 50% of the data and train the rest 50% of the model.

Leave One Out Cross Validation

This method identifies one data point from the set of data and trains the remaining data. It then loops through the entire data set, omitting one data point each time. The average is then used to calculate the score. This method will consume a lot of time and a large number of computer resources.

K-Fold

Finally, there is K-Fold. K-Fold cross validation requires a number, k, that indicates how and where to split your data. Let’s start with k = 5. As a result, the data is divided into five categories. The first 20% would be regarded as test data, while the remaining 80% would be regarded as train data. It then tends to take the next 20%, with the remaining 80% being test data and so on. It then computes a score by using the average of all five data sets.

These are the common cross validation techniques in regression models.

Importance of Cross Validation in Machine Learning

When your original validation partition doesn’t really represent the whole population, you get a model with a high degree of accuracy.

However, because it can only work with a specific set of data, it will be of little use in practice. The machine cannot recognize data that is outside of its scope, resulting in poor accuracy.

Cross validation in machine learning is used to test the accuracy of your model on multiple and diverse subsets of data. As a result, you must ensure that it extends effectively to the data. It improves the accuracy of the model.

Limitations of Cross Validation techniques

We learned about cross validation in machine learning and realized how important it is. It is an important element of machine learning, but it is not without limitations.

  • In an ideal world, cross validation would produce precise and meaningful results. Nevertheless, the world is not without flaws. You never know what data the model will come across in the future.
  • In predictive modeling, the framework under study generally changes over time. As a result, there may be discrepancies between both the training and validation sets. Assume you have such a model that forecasts stock prices. You used data from the previous five years to train the model. Is it reasonable to expect precise forecasts over the next five years?
  • And here is another case where the limitations of cross validation processes are highlighted. You create a model that predicts an individual’s risk of developing a specific disease. However, you train the model with data from a study that included a subset of the population. When the model is applied to the general public, the results may vary significantly.

Application of cross validation techniques

  • Cross validation can be used to compare the results of a set of predictive methods.
  • It is extremely useful in medical research. Consider how we predict whether a cancer patient would then respond to a particular drug based on the expression levels of a specified number of proteins, let’s say 15. The best approach is to figure out which subset of the 15 features produces the best predictive model. You can use cross validation to identify the specific subset that produces the best results.
  • In the area of medical statistics, data analysts have recently used cross validation. These procedures are beneficial in meta-analysis.

Cross Validation in Python

Python supports cross validation. It can help prevent overfitting and underfitting. Now let’s look at some cross validation applications in Python.

Overfitting occurs once the model is trained “too well.” It occurs when there is a complex model with a large number of variables in contrast to the number of observations.

In such cases, the model will perform admirably in training mode but may be inaccurate when applied to new data. It is because of the fact that it is not a simplistic model.

Underfitting, as opposed to overfitting, takes place when the model doesn’t really fit the training data. As a result, it cannot be generalized to new data.

It’s because you’re staring at a basic model with insufficient independent variables. It can also occur when fitting a linear model to non-linear data.

In data analysis, overfitting and underfitting are both undesirable. Always strive for a sensible approach or a model that is “just right.” Cross-validation can assist you in avoiding overfitting and underfitting.

These problems can be solved using the K-Fold Cross Validation and LOOCV processes. We’ve all seen how these procedures operate. The K-Fold CV method is depicted graphically below.

You have ten different outcomes. To determine the final accuracy figure, take the average of the ten results.

Machine learning necessitates extensive data analysis. Cross validation techniques are an excellent method for preparing the machine for real-world situations.

As a result, the machine is prepared to integrate new data and generalize it in order to make accurate predictions. Join the Machine Learning with Python Course to learn about machine learning and Python fundamentals.

Conclusion

In this article, we have learned about the importance of Validation of a Machine Learning Model in the Data Science Project Life Cycle, got to know what is validation and cross-validation, explored the different types of Cross-Validation techniques, got to know some advantages and disadvantages of those techniques.

If you’re interested to learn more about machine learning, check out IIIT-B & upGrad’s PG Diploma in Machine Learning & AI which is designed for working professionals and offers 450+ hours of rigorous training, 30+ case studies & assignments, IIIT-B Alumni status, 5+ practical hands-on capstone projects & job assistance with top firms.

Frequently Asked Questions (FAQs)

1. What is the need for cross-validation in machine learning?

Cross-validation is a machine learning technique where the training data is split into two parts: A training set and a test set. The training set is used to build the model, and the test set is used to evaluate how well the model performs when in production. The reason for doing this is that there is a risk that the model that you have built does not perform well in the real world. If you do not cross-validate your model, there is a risk that you have built a model that works great on the training data, but doesn't perform well on the real-world data.

2. What is k-fold cross validation?

In machine learning and data mining, k-fold cross validation, sometimes called leave-one-out cross-validation, is a form of cross-validation in which the training data is divided into k approximately equal subsets, with each of the k-1 subsets used as test data in turn and the remaining subset used as training data. K is often 10 or 5. K-fold cross-validation is particularly useful in model selection, since it reduces the variance of the estimates of the generalization error.

3. What are the advantages of cross validation?

Cross validation is a form of validation in which the dataset is partitioned into a training set and a test set (or cross-validation set). This set is then used to test the accuracy of your model. In other words, it gives you a methodology to measure how good your model is based on a sample of your data. For example, it is used to estimate the error of the model which is induced by the discrepancy between the training input and the testing input.