Which regularization technique, Lasso or Ridge, provides a better solution for a predictive regression model based on the resulting photo?
Show older comments
In the photo, the variables [minMSEL, idxL] represent the minimum mean squared error (MSEL) values obtained for the ridge and lasso models, respectively. Considering overfitting and better prediction, which of the two models demonstrates superior performance based on these results?

Fuel Economy - Regularized Linear Models
Instructions are in the task pane to the left. Complete and submit each task one at a time.
This code loads the data.
load carEcon
whos XTrain XTest econTrain econTest
Task 1
Fit ridge model
lambdaR = 0:300;
bR = ridge(econTrain,XTrain,lambdaR,0);
Task 2
Calculate and plot MSE. Find smallest MSE.
econPredR = bR(1,:) + XTest*bR(2:end,:);
err = econPredR - econTest;
MSER = mean(err.^2);
[minMSER,idxR] = min(MSER)
plot(lambdaR,MSER)
xlabel("\lambda")
ylabel("MSE")
title("Ridge model")
Task 3
Fit lasso model
lambdaL = (0:300)/length(econTrain);
[bL,fitInfo] = lasso(XTrain,econTrain,"Lambda",lambdaL);
Task 4
Calculate and plot MSE. Find smallest MSE.
econPredL = fitInfo.Intercept + XTest*bL;
err = econPredL - econTest;
MSEL = mean(err.^2);
[minMSEL,idxL] = min(MSEL)
plot(lambdaL,MSEL)
xlabel("\lambda")
ylabel("MSE")
title("Lasso model")
5 Comments
the cyclist
on 24 Jun 2023
What is your MATLAB question for us?
Mohammadreza
on 25 Jun 2023
the cyclist
on 25 Jun 2023
Your question is about machine learning, and not really a MATLAB question.
I assume that this is your homework, and you are stuck. (Perhaps this is "Task 5"?) Here is a hint: What you are interested in, for "superior performance", is the generalization error. That relates to performance on the test set.
Mohammadreza
on 25 Jun 2023
the cyclist
on 26 Jun 2023
idxR and idxL are just the indices to which element has the minimum MSE.
Because you are calculating the MSE on the test set, and not the training set, I would not be too concerned with overfitting.
The lasso model also typically has a simpler interpretation, because it shrinks coefficients all the way to zero, dropping them out of the model completely.
There are nuances and subtleties in all of this, but it would be too much to explain in this forum.
Answers (0)
Categories
Find more on Support Vector Machine Regression in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!