Skip to content
Advertisement

K-Fold cross validation for Lasso and Ridge models

I’m working with the Boston housing dataset from sklearn.datasets and have run ridge and lasso regressions on my data (post train/test split). I’m now trying to perform k-fold cross validation to find the optimal penalty parameters, and have written the code below. What can I do to resolve this issue and find the optimal penalty parameters using K-fold validation for Ridge and Lasso regressions? Thank you.

JavaScript

which then produces the error message of:

JavaScript

Advertisement

Answer

I set up the dataset with Boston as below:

JavaScript

If I do cv lasso, i do not get the error you see, try not to run with alpha = 0, this is not lasso:

JavaScript

Then:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement