Code

sklearn.model_selection.cross_val_score

from sklearn.model_selection import cross_val_score cv_scores = cross_val_score(clf, X, y, cv=5)

Where:

  • clf: The estimator/model object to evaluate.
  • X: The input data (features) to fit.
  • y: The target variable/labels.
  • cv: The number of folds for cross-validation (defaults to 5).

The function returns an array of scores (such as accuracy) for each of the KK folds. The average performance of the model can be calculated using cv_scores.mean().

0

3

Updated 2026-07-03

Tags

Helpful Scikit-Learn functions

Data Science