Restricting Lasso-coefficients
13 次查看(过去 30 天)
显示 更早的评论
Hello all,
I am currently working on a Finance-application of Lasso. However, for my purpose I would need to restrict the coefficients obtained from the lasso(X,y)-command to be larger or equal to zero.
How can I achieve this?
My initial trial is to copy and change the existing lasso-function. In the subfunction lassoFit(), I find the command:
B(:,i) = b;
Now, before this I would simply add:
b(b<0) = 0; % restrict b to be larger/ equal to 0
B(:,i) = b;
However, I am not really sure if this is correct and any help would be highly appreciated.
Many thanks.
Best
Max
0 个评论
回答(1 个)
Pravin Jagtap
2019-9-16
Hello Miximilian,
To fit the data, it is important to understand how different models of regression work and what is the effect of regularization term on overall error minimization function. Please refer to following documentation for detail understanding of error minimization objectives:
In order to achieve non-negative coefficients, try exploring some other methods such as ridge regression, weighted least squares, etc. because ‘lasso’ algorithm uses the square loss function which has less tendency of hitting coefficients at zero than ridge regression (Understand the geometric meaning of ‘L1’ and ‘L2’ loss functions and optimization using it). Enforcing the constraints provided by you is similar to changing the overall objective function of ‘lasso’ regression mathematically.
Kind Regards
~Pravin
1 个评论
John D'Errico
2019-9-16
I would add that it is rarely a good idea to modify existing toolbox code. Unless of course, you know enough to have written the code yourself. And even then, it is a dangerous thing to do. As you might introduce bugs into the code, or someone in the future will use your function, not knowing that it was hacked to do something that is not in the documentation.
So, if you know enough to write the code yourself, then the best thing is to write it yourself anyway. Write a simple version, that does exactly what you need.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!