Something wrong in fitrlinear with ridge regularization?

There is something wrong in the attached code. I couldn't figure out where it went wrong. Any help is highly appreciated!

5 件のコメント

Prince Kumar
Prince Kumar 2022 年 3 月 31 日
Can you share the error as well?
Peter He
Peter He 2022 年 3 月 31 日
Hi Prince,
Thank you for looking into this.
There is no syntax error but rather a semantic error maybe. I explained the error in the live script - the result of setting "Lambda" to 0 for ridge regression should return a model exactly the same as the linear model w/o regularization/shrinkage. But I get a much worse model instead. Here is the line that I tested the above point in the attached code:
mdl2=fitrlinear(X(idxTrain,:),y(idxTrain),'Learner','leastsquares','Regularization','ridge','Lambda',0);
I got mse = 54.3139
if I use the following:
mdl = fitlm(X(idxTrain,:),y(idxTrain));
I got mse = 16.8294, which is significantly better. I also plotted the observed vs. fitted, which also shows very poor fitting for ridge regression.
Peter He
Peter He 2022 年 3 月 31 日
I'm not sure if there is any scaling involved for the predictors - I couldn't find any information from the document of this function. But it seems that the response is not scaled. Just a potential issue I have thought about but haven't tested.
Biral Pradhan
Biral Pradhan 2022 年 9 月 28 日
The "fitrlinear" method uses iterative solvers that converge subject to tolerances on beta coefficients and gradient. In this case, optimization doesn't occur because the first step does not move the beta estimates away from the initial zero values far enough. Kindly set the "BetaTolerance" parameter to a lower value, say 1e-6 in order to resolve this issue. For more information, kindly follow the below documentation link:
I would also recommend setting "Verbose" to 1 in order to obtain more information throughout the optimization process.
Peter He
Peter He 2023 年 12 月 31 日
Thank you Biral. That indeed was the problem. Here is a link to a related question that I asked and got a similar answer to it. But I was able to verify the problem using that example.
Thanks again.
Peter

サインインしてコメントする。

 採用された回答

Peter He
Peter He 2023 年 12 月 31 日

0 投票

Thank you Biral. That indeed was the problem. Here is a link to a related question that I asked and got a similar answer to it. But I was able to verify the problem using that example.
Thanks again.
Peter

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

リリース

R2020a

質問済み:

2022 年 3 月 28 日

回答済み:

2023 年 12 月 31 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by