Cross-validation is a resampling technique used to evaluate the performance of machine learning models on limited data. It involves splitting the available data into multiple subsets or folds. The model is trained on a combination of folds and evaluated on the remaining fold. This process is repeated multiple times, with each fold serving as the validation set. Cross-validation helps in estimating the model's performance and detecting issues such as overfitting.
Example code:
# Example code illustrating cross-validation using k-fold
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LogisticRegression
logistic_model = LogisticRegression()
scores = cross_val_score(logistic_model, X, y, cv=5) # cv is the number of folds
print("Cross-Validation Scores:", scores)