---
source: https://iinventedlight.com/library/notes/sklearn-cross-validation.md
title: "Cross-validation in scikit-learn"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (scikit-learn/scikit-learn COPYING; Copyright (c) 2007-2026 The scikit-learn developers; https://github.com/scikit-learn/scikit-learn/blob/main/COPYING); prose restates or closely paraphrases cited source lines"
license_family: sklearn-bsd3
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "Summary by iinventedlight (AI-assisted). Sources: scikit-learn docs, 3.1. Cross-validation: evaluating estimator performance — scikit-learn 1.9.1 documentation, BSD-3-Clause (scikit-learn/scikit-learn COPYING; Copyright (c) 2007-2026 The scikit-learn developers; https://github.com/scikit-learn/scikit-learn/blob/main/COPYING); scikit-learn docs, Getting Started — scikit-learn 1.9.1 documentation, BSD-3-Clause (scikit-learn/scikit-learn COPYING; Copyright (c) 2007-2026 The scikit-learn developers; https://github.com/scikit-learn/scikit-learn/blob/main/COPYING)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: scikit-learn"
tags: ['scikit-learn', 'cross-validation', 'model-evaluation']
sources:
  - id: S1
    title: "3.1. Cross-validation: evaluating estimator performance — scikit-learn 1.9.1 documentation"
    publisher: scikit-learn docs
    url: https://scikit-learn.org/stable/modules/cross_validation.html
    accessed: 2026-11-04
    license: "BSD-3-Clause (scikit-learn/scikit-learn COPYING; Copyright (c) 2007-2026 The scikit-learn developers; https://github.com/scikit-learn/scikit-learn/blob/main/COPYING)"
  - id: S2
    title: "Getting Started — scikit-learn 1.9.1 documentation"
    publisher: scikit-learn docs
    url: https://scikit-learn.org/stable/getting_started.html
    accessed: 2026-11-04
    license: "BSD-3-Clause (scikit-learn/scikit-learn COPYING; Copyright (c) 2007-2026 The scikit-learn developers; https://github.com/scikit-learn/scikit-learn/blob/main/COPYING)"
---
# Cross-validation in scikit-learn

**Answer:** The simplest way to use cross-validation is to call the cross_val_score helper function on the estimator and the dataset. The performance measure reported by k-fold cross-validation is then the average of the values computed in the loop. (S1)

## Splitting and scoring

- In scikit-learn a random split into training and test sets can be quickly computed with the train_test_split helper function. (S1)
- By default, the score computed at each CV iteration is the score method of the estimator. (S1)
- When cv is an integer, KFold or StratifiedKFold strategies are used by default, the latter being used if the estimator derives from ClassifierMixin. (S1)
- cross_validate returns a dict containing fit-times, score-times (and optionally training scores, fitted estimators, train-test split indices) in addition to the test score. (S1)

## Beyond the helpers

- scikit-learn provides many other tools for model evaluation, in particular for cross-validation, beyond train_test_split. (S2)
- It is also possible to manually iterate over the folds, use different data splitting strategies, and use custom scoring functions. (S2)
- Using a pipeline for cross-validation and searching will largely keep you from the common pitfall of leaking test data into training. (S2)

## Claims
- id: C1
  claim: cross_val_score is the simplest way to cross-validate.
  source: S1
  evidence: "The simplest way to use cross-validation is to call the"
- id: C2
  claim: The default CV score is the estimator's score method.
  source: S1
  evidence: "the score computed at each CV iteration is the score"
- id: C3
  claim: cross_validate also returns fit and score times.
  source: S1
  evidence: "It returns a dict containing fit-times, score-times"
- id: C4
  claim: You can use custom scoring functions.
  source: S2
  evidence: "and use custom scoring functions."

## Sources
- [S1] 3.1. Cross-validation: evaluating estimator performance — scikit-learn 1.9.1 documentation. scikit-learn docs. https://scikit-learn.org/stable/modules/cross_validation.html . License: BSD-3-Clause (scikit-learn/scikit-learn COPYING; Copyright (c) 2007-2026 The scikit-learn developers; https://github.com/scikit-learn/scikit-learn/blob/main/COPYING). Accessed 2026-11-04.
- [S2] Getting Started — scikit-learn 1.9.1 documentation. scikit-learn docs. https://scikit-learn.org/stable/getting_started.html . License: BSD-3-Clause (scikit-learn/scikit-learn COPYING; Copyright (c) 2007-2026 The scikit-learn developers; https://github.com/scikit-learn/scikit-learn/blob/main/COPYING). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
