Sklearn RidgeCV - Training a Ridge Regression Model With Cross Validation

Python

In this example we'll train a regression model using RidgeCV. This fits a ridge regression model but tunes the alpha parameter.

In this instance we train with alpha values of 0.5 and 1 using a 3-fold cross validation strategy and cross validate using the mean squared error metric.

 1|  from sklearn.linear_model import RidgeCV
 2|  
 3|  # initialise & fit a RidgeCV regression model
 4|  model = RidgeCV(alphas=[0.5, 1],
 5|                 scoring='neg_mean_squared_error',
 6|                 cv=3)
 7|  model.fit(X_train, y_train)
Did you find this snippet useful?

Sign up for free to to add this to your code library