Regularization selection
Choose ridge regularization automatically instead of manually tuning one value.
Scikit-Learn · Class
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.
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.
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)| Name | Type | Description |
|---|---|---|
alphas | array-like of shape (n_alphas,) | Candidate regularization strengths; each must be a positive float. Default: (0.1, 1.0, 10.0). |
fit_intercept | bool | Whether to fit an intercept. Default: True. |
scoring | str or callable | Scoring method used for cross-validation. Default: None. |
cv | int, cross-validation generator, iterable, or None | Cross-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_results | bool | Whether to store cross-validation results. Default: False. |
alpha_per_target | bool | Whether to use a separate alpha for each target. Default: False. |
A fitted RidgeCV estimator with the selected alpha and fitted regression coefficients.
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.
Choose ridge regularization automatically instead of manually tuning one value.
Use leave-one-out validation efficiently on regression data.
Evaluate models with a custom metric or validation splitter.
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.
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.
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.
RidgeRidgeClassifierCVRidgeClassifierKFoldStratifiedKFold