Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Function

validation_curve

Evaluate an estimator across values of one parameter and collect cross-validation training and test scores. The result helps reveal how that parameter affects model performance.

How it works

The function clones and evaluates an estimator for every value in param_range. Cross-validation produces one training-score and one test-score for each parameter value and fold, using the estimator’s default scorer unless scoring is supplied.

Syntax

sklearn.model_selection.validation_curve(estimator, X, y, *, param_name, param_range, groups=None, cv=None, scoring=None, n_jobs=None, pre_dispatch='all', verbose=0, error_score=nan, params=None)

Parameters

NameTypeDescription
estimatorestimator objectEstimator implementing fit and predict; it is cloned for each validation.
Xarray-likeTraining input samples.
yarray-likeTarget values.
param_namestrName of the estimator parameter to vary.
param_rangearray-like of shape (n_values,)Candidate values to evaluate for the selected parameter.
groupsarray-like, default=NoneGroups used by the cross-validation splitter, when applicable.
cvint, cross-validation generator or iterable, default=NoneCross-validation splitter specification.
scoringstr, callable or None, default=NoneScoring strategy; defaults to the estimator’s score method when omitted.
n_jobsint, default=NoneNumber of jobs run in parallel.
pre_dispatchint or str, default='all'Number of jobs dispatched ahead of execution.
verboseint, default=0Controls the verbosity of parallel execution.
error_score‘raise’ or numeric, default=nanValue assigned when a fitting or scoring error occurs.

Returns

A tuple containing train_scores and test_scores, each an array of shape (n_ticks, n_cv_folds).

Key points

  • The function compares training and test performance while one estimator parameter changes.
  • param_name identifies the parameter under study, while param_range supplies the candidate values.
  • It is suitable for examining a single hyperparameter’s effect rather than tuning several parameters together.
  • Both score outputs contain one row per parameter value and one column per cross-validation fold.
  • cv selects how the data is partitioned into training and test portions.
  • The estimator is independently cloned for validation runs, so each evaluation starts from a fresh model.

Common mistakes

  • It evaluates one parameter at a time and returns raw fold scores; it is intended as a plotting utility rather than a general multi-parameter search.
  • Every value in param_range must be a valid value for the estimator parameter named by param_name.
  • The second returned array contains cross-validation test scores, not predictions or a single aggregate score.

Example: Evaluate a validation curve

import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import validation_curve
from sklearn.svm import SVC

X, y = load_iris(return_X_y=True)
train_scores, test_scores = validation_curve(
    SVC(kernel="linear"),
    X,
    y,
    param_name="C",
    param_range=np.logspace(-3, 2, 5),
    cv=5,
    scoring="accuracy",
)
print(train_scores.shape, test_scores.shape)

Evaluates a linear SVM across five C values and five cross-validation folds, returning training and test scores for each combination.

When to use it

Compare training and validation behavior

Diagnose whether changing one hyperparameter improves generalization.

Build a validation curve

Create a plot of model performance across regularization or complexity values.

Measure cross-validation variability

Inspect fold-level variation for a single parameter sweep.

Interview questions

QWhat does validation_curve compute?

validation_curve evaluates an estimator over several values of one named parameter and returns training and test scores. It resembles a one-parameter grid search, but also reports training scores and is mainly useful for plotting.

Follow-up: How would you inspect variability across folds? Use the returned arrays’ fold dimension to compute a mean and spread for each parameter value.

QWhat are the return shapes?

The returned train_scores and test_scores have shape (n_ticks, n_cv_folds). Each row corresponds to one value from param_range, and each column corresponds to one cross-validation fold.

Follow-up: What should be plotted? Typically plot the mean across folds against param_range, with dispersion such as standard deviation shown separately.

QHow are folds and scoring selected?

cv controls the cross-validation splitting strategy and may be an integer, a cross-validation generator, or an iterable. If cv is omitted, the function uses its documented default splitting behavior.

Follow-up: How can evaluation use a custom metric? Pass a scorer through scoring, such as a scorer name or callable accepted by scikit-learn.

  • sklearn.model_selection.ValidationCurveDisplay
  • sklearn.model_selection.cross_validate
  • sklearn.model_selection.GridSearchCV
  • sklearn.model_selection.learning_curve

Source: validation_curve — scikit-learn 1.9.1 documentation. Checked 2026-10-15.