Thursday, April 23, 2026

What is cross validation? An ordinary English guide with diagrams

Share

What is cross validation? An ordinary English guide with diagrams
Photo by the editor

# Entry

One of the most hard elements of machine learning is not to create the model itself, but to assess its performance.

The model may look great in one division of the train/test, but it breaks down when it is used in practice. The reason is that a single division is testing the model only once, and this test set may not capture the full variability of data it will encounter in the future. As a result, the model may seem better than in reality, which leads to excessive fit or misleading high results. This is where the Cross validation appears.

In this article, we will break the cross validation in ordinary English, give the reasons why it is more reliable than the method of suspension, and we show how to utilize it with basic code and images.

# What is cross validation?

Cross validation is a procedure for checking the correctness of machine learning to assess the performance of the model using many data subsets, as opposed to only one subset. The basic idea of ​​this concept is to provide each data point with a chance to appear in the training set and a set of tests as part of determining the final performance. The model is therefore evaluated many times using various divisions, and the selected performance measure is then averaged.

What is cross validation? An ordinary English guide with diagramsWhat is cross validation? An ordinary English guide with diagrams
Photo by the author

The main advantage of cross -validation during one division of the train test is that it estimates the efficiency of cross validation, because it allows you to average the performance of the model for folds, smoothing randomness in which the points have been put aside as a test set.

Simply put, there may be one set of tests to contain examples that lead to the extremely high accuracy of the model or occur in such a way that with another combination of examples it would lead to extremely low performance. In addition, the Cross Validation uses our data better, which is crucial if you work with compact data sets. Cross validation does not require waste of valuable information, putting aside a vast part. Instead, cross -validation means that the same observation can play the role of a train or test at different times. Simply put, the model takes many mini-projects, as opposed to one vast test.

What is cross validation? An ordinary English guide with diagramsWhat is cross validation? An ordinary English guide with diagrams
Photo by the author

# The most common types of cross validation

There are different types of cross validation, and here we will look at the four most common.

// 1. K-Fold Cross-Walidation

The most famed method of cross validation is K-Fold Cross-Validation. In this method, the data set is divided into equal parts, also known as folds. The model is trained on K-1 folds and tested on a skipped fold. The process continues until each fold is not set by the test. The results of all folds are averaged together, creating a stable measure of the model’s accuracy.

For example, in a 5-fold Cross validation, the data set will be divided into five parts, and each part becomes a test set once before everything is averaged to calculate the final performance assessment.

What is cross validation? An ordinary English guide with diagramsWhat is cross validation? An ordinary English guide with diagrams
Photo by the author

// 2. Stratified K-Fold

In the case of problems with the classification, in which real data sets are often unbalanced, the stratified cross-validation K. In the standard K-Fold, we can happen that with a test fold with a highly distorted distribution of classes, for example, if one of the test folds has very few class B-class instances or without them. Stratified K-Fold guarantees that all folds are approximately the same proportions of the class. If your data set has 90% A class and 10% B class, each fold will have about 90% in this case: 10%, which gives a more coherent and fair grade.

What is cross validation? An ordinary English guide with diagramsWhat is cross validation? An ordinary English guide with diagrams
Photo by the author

// 3. Validation of the crossing

Cross validation (LOOCV) is an extreme K-Fold case, in which the number of folds is equal to the number of data points. This means that for each course the model is trained in all observations except one, and a single observation is used as a test set.

The process is repeated until each point is tested once and the results are averaged. LOOCV can provide almost objective performance estimates, but it is extremely high-priced to calculate on larger data sets, because the model must be trained as many times as there are data points.

What is cross validation? An ordinary English guide with diagramsWhat is cross validation? An ordinary English guide with diagrams
Photo by the author

// 4. Validation of the cross ranks

Instead, the folds are built chronologically using the expanding window (gradually increasing the size of the training set) or turning window (maintaining a constant training set, which moves forward with time). This approach respects time dependencies and gives realistic performance estimates for forecasting tasks.

What is cross validation? An ordinary English guide with diagramsWhat is cross validation? An ordinary English guide with diagrams
Photo by the author

# Compromise and validation of the cross

Cross validation is far away to solve the compromise of prejudices in the field of model assessment. Thanks to the division of one train test, the performance estimation variance is high, because the result depends to a vast extent on which poems end in the test set.

However, when you utilize cross validation, average performance in many test sets, which reduces variance and gives a much more stable estimation of the model’s performance. Certainly the cross -validation of the cross will not completely eliminate bias, because no amount of cross validation will solve a set of data with bad labels or systematic errors. But in almost all practical cases it will be a much better approximation of the performance of your model on unseen data than one test.

# Example in Python with Scikit-Learn

This tiny example is trained by a logistic regression model on the IRIS data set with 5-fold cross validation (by Scikit-Learn). The output shows the results for each fold and average accuracy, which is much more indicating performance than any one -off test.

from sklearn.model_selection import cross_val_score, KFold
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_iris

X, y = load_iris(return_X_y=True)
model = LogisticRegression(max_iter=1000)

kfold = KFold(n_splits=5, shuffle=True, random_state=42)
scores = cross_val_score(model, X, y, cv=kfold)

print("Cross-validation scores:", scores)
print("Average accuracy:", scores.mean())

# Wrapping

Cross validation is one of the most solid techniques for assessing machine learning models, because it turns one data test into many data tests, which gives a much more reliable picture of the model performance. Unlike the method of suspension or a single division of the train test, it reduces the likelihood of excessive adaptation to one data partition and uses each element of data better.

When we finish this, some of the best practices to keep in mind are:

  • Put your data before parting (except for the time series)
  • Utilize a stratified K-Fold for classification tasks
  • Watch out for calculation costs with a vast K or LOOCV
  • Prevent data leaks by matching scalers, encoders and selecting functions only in training folds

When developing the next model, remember that simply relying on one test set can be full of misleading interpretations. Using Krzyżowa K or similar methods will lend a hand you better understand how your model can work in the real world, and that’s what counts.

Josep Ferrer He is an analytical engineer from Barcelona. He graduated from physics engineering and is currently working in the field of data learning used for human mobility. He is the creator of part -time content focused on learning data and technology. Josep writes about all AI things, including the utilize of a ongoing explosion in the field.

Latest Posts

More News