## assess and improve predictive performance of models

cross-validation is a model assessment technique used to evaluate a machine learning algorithm’s performance in making predictions on new datasets that it has not been trained on. this is done by partitioning the known dataset, using a subset to train the algorithm and the remaining data for testing.

each round of cross-validation involves randomly partitioning the original dataset into a *training set* and a *testing set*. the training set is then used to train a supervised learning algorithm and the testing set is used to evaluate its performance. this process is repeated several times and the average cross-validation error is used as a performance indicator.

### why is cross-validation important?

when training a model, it is important not to overfit or underfit it with algorithms that are too complex or too simple. your choice of training set and test set are critical in reducing this risk. however, dividing the dataset to maximize both learning and validity of test results is difficult. this is where cross-validation comes into practice. cross-validation offers several techniques that split the data differently, to find the best algorithm for the model.

cross-validation also helps with by calculating the error using the testing dataset, which has not been used to train. the testing dataset helps calculate the accuracy of the model and how it will generalize with future data.

### common cross-validation techniques

many techniques are available for cross-validation. among the most common are:

**k-fold**: partitions data into k randomly chosen subsets (or folds) of roughly equal size. one subset is used to validate the model trained using the remaining subsets. this process is repeated k times such that each subset is used exactly once for validation. the average error across all k partitions is reported as ε. this is one of the most popular techniques for cross-validation but can take a long time to execute because the model needs to be trained repeatedly. the image below illustrates the process.

**holdout**: partitions data randomly into exactly two subsets of specified ratio for training and validation. this method performs training and testing only once, which cuts execution time on large sets, but interpret the reported error with caution on small data sets.**leaveout**: partitions data using the k-fold approach where k is equal to the total number of observations in the data and all data will be used once as a test set. also known as leave-one-out cross-validation (loocv).**repeated random sub-sampling**: creates multiple random partitions of data to use as training set and testing set using the monte carlo methodology and aggregates results over all the runs. this technique has a similar idea as the k-fold but each test set is chosen independently, which means some data points might be used for testing more than once.**stratify**: partitions data such that both training and test sets have roughly the same class proportions in the response or target.**resubstitution**: does not partition the data and all data is used for training the model. the error is evaluated by comparing the outcome against actual values. this approach often produces overly optimistic estimates for performance and should be avoided if there is sufficient data.

cross-validation can be a computationally intensive operation since training and validation is done several times. however, it is a critical step in model development to reduce the risk of overfitting or underfitting a model. because each partition set is independent, you can perform this analysis in parallel to speed up the process. for larger datasets, techniques like holdout or resubstitution are recommended, while others are better suited for smaller datasets such as k-fold and repeated random sub-sampling.

### cross-validation with matlab

matlab^{®} supports cross-validation and machine learning. you can use some of these cross-validation techniques with the classification learner app (4:34) and the .

to speed computationally intensive operations, you can perform parallel computations on multicore computers, gpus, and clusters with parallel computing toolbox™.

for more information on using cross-validation with machine learning problems, see statistics and machine learning toolbox™ and deep learning toolbox™ for use with matlab.

### examples and how to

**ebooks and articles**

**examples**

**videos**

### software reference

*see also:
statistics and machine learning toolbox,
machine learning,
supervised learning,
feature selection,
regularization,
linear model,
roc curve
*