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

Scikit-Learn · Class

RidgeCV

RidgeCV fits ridge regression while selecting the best regularization strength by cross-validation. It defaults to efficient leave-one-out cross-validation and supports custom scoring and validation strategies.

How it works

RidgeCV evaluates candidate regularization strengths and fits a ridge regression model using the best one. With the default cross-validation setting, it uses efficient leave-one-out cross-validation; passing cv changes the validation strategy.

Syntax

class sklearn.linear_model.RidgeCV(alphas=(0.1, 1.0, 10.0), *, fit_intercept=True, scoring=None, cv=None, gcv_mode='auto', store_cv_results=False, alpha_per_target=False)

Parameters

NameTypeDescription
alphasarray-like of shape (n_alphas,)Candidate regularization strengths; each must be a positive float. Default: (0.1, 1.0, 10.0).
fit_interceptboolWhether to fit an intercept. Default: True.
scoringstr or callableScoring method used for cross-validation. Default: None.
cvint, cross-validation generator, iterable, or NoneCross-validation strategy: None, an integer, a splitter, or an iterable of train/test index splits. Default: None.
gcv_mode{'auto', 'svd', 'eigen'}Leave-one-out strategy: 'auto', 'svd', or 'eigen'. Default: 'auto'.
store_cv_resultsboolWhether to store cross-validation results. Default: False.
alpha_per_targetboolWhether to use a separate alpha for each target. Default: False.

Returns

A fitted RidgeCV estimator with the selected alpha and fitted regression coefficients.

Key points

  • The class combines ridge regression and internal cross-validation to choose among candidate regularization strengths.
  • When cv is omitted, the default validation procedure is efficient leave-one-out cross-validation.
  • alphas defines the candidate values evaluated during model selection.
  • fit_intercept determines whether the fitted model includes an intercept.
  • scoring specifies how validation performance is measured.
  • gcv_mode selects the leave-one-out computation strategy when applicable.

Common mistakes

  • Every value supplied in alphas must be positive.
  • gcv_mode controls the strategy used specifically for leave-one-out cross-validation.
  • For integer or default cv settings, classification targets use stratified folds while other targets use ordinary K-fold splits.

Example: Choose ridge regularization by cross-validation

from sklearn.datasets import load_diabetes
from sklearn.linear_model import RidgeCV

X, y = load_diabetes(return_X_y=True)
model = RidgeCV(alphas=[1e-3, 1e-2, 1e-1, 1.0]).fit(X, y)
print(model.alpha_)
print(model.score(X, y))

Loads a regression dataset, selects the best regularization strength by cross-validation, fits the model, and prints the selected alpha and training score.

When to use it

Regularization selection

Choose ridge regularization automatically instead of manually tuning one value.

Default cross-validation

Use leave-one-out validation efficiently on regression data.

Custom model selection

Evaluate models with a custom metric or validation splitter.

Interview questions

QWhat does RidgeCV do?

RidgeCV performs ridge regression while selecting a regularization strength from the supplied alphas through cross-validation. By default, it uses efficient leave-one-out cross-validation.

Follow-up: How would you use ordinary K-fold validation instead? Pass an integer or a cross-validation splitter through cv.

QHow is the regularization strength selected?

alphas is the candidate array of regularization strengths. The estimator chooses the value producing the best cross-validation result and exposes that choice through alpha_.

Follow-up: What constraint applies to candidates? Each alpha must be a positive float.

QWhat forms can cv take?

cv accepts None, an integer, a cross-validation splitter, or an iterable of train/test index splits. None selects efficient leave-one-out cross-validation.

Follow-up: Which splitters are selected for an integer or None? StratifiedKFold is used for binary or multiclass y; otherwise KFold is used.

  • Ridge
  • RidgeClassifierCV
  • RidgeClassifier
  • KFold
  • StratifiedKFold

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