Restricting Lasso-coefficients
5 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Pravin Jagtap
on 16 Sep 2019
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 Comment
John D'Errico
on 16 Sep 2019
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.
See Also
Categories
Find more on Gaussian Process Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!