Ridge regression is a type of linear regression that adds a penalty term to the coefficients, restricting the model from overfitting the data. In scikit-learn, we can use the RidgeCV
class to fit a Ridge regression model with cross-validated alpha selection.
Here's an example of how to use RidgeCV
with cross-validation:
main.py453 chars16 lines
In this example, we loaded the Boston Housing dataset, initialized a RidgeCV
model with a few different values of alpha, and fit the model with 5-fold cross-validation. The cross_val_score
function returns an array of scores for each fold, so we printed the mean score across all folds.
gistlibby LogSnag