LASSO function not behaving as expected
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I've been performing LASSO regulerisation but it has been behaving oddly. Code that once works no longer is, and now I can't even get the example from Matlab help to work. For instance here's some data:
rng default % For reproducibility
X = randn(100,5);
weights = [0;2;0;-3;0]; % Only two nonzero coefficients
y = X*weights + randn(100,1)*0.1; % Small added noise
Following he documentation verbatim,
B = lasso(X,y);
B(:,25)
returns the error:
Index in position 2 exceeds array bounds (must not exceed 6).
because when I run it the results are:
B =
0 0 0 0 -0.0067 -0.0067
0 0 1.9802 1.9838 1.9919 1.9920
0 0 0 -0.0039 -0.0109 -0.0109
0 -0.6818 -2.9817 -2.9865 -2.9958 -2.9959
0 0 0 0 0 0.0001
So is the documentation incorrect or is something else going on here?
Additionally, the function doesn't seem to accept values for lambda, for example:
B = lasso(X,y)
C = lasso(X,y,'Lambda', 0.18)
D = lasso(X,y,'Lambda',linspace(0,1))
gives:
B =
0 0 0 0 -0.0067 -0.0067
0 0 1.9802 1.9838 1.9919 1.9920
0 0 0 -0.0039 -0.0109 -0.0109
0 -0.6818 -2.9817 -2.9865 -2.9958 -2.9959
0 0 0 0 0 0.0001
C =
0 0 0 0 -0.0067 -0.0067
0 0 1.9802 1.9838 1.9919 1.9920
0 0 0 -0.0039 -0.0109 -0.0109
0 -0.6818 -2.9817 -2.9865 -2.9958 -2.9959
0 0 0 0 0 0.0001
Operands to the || and && operators must be convertible to logical scalar values.
Error in larsen (line 197)
if storepath && size(b,2) > step
Error in lasso (line 119)
[b steps] = larsen(X, y, 0, stop, Gram, storepath, verbose);
C is returning an identical result despite a single value for lambda being given. And why is D producing an error - especially when this is the syntax given in the LASSO help page.
Any pointers would be appreciated.
2 commentaires
Image Analyst
le 19 Jan 2021
Give us the code, in a single snippet, that runs and gives the error, because this:
rng default % For reproducibility
X = randn(100,5);
weights = [0;2;0;-3;0]; % Only two nonzero coefficients
y = X*weights + randn(100,1)*0.1; % Small added noise
B = lasso(X,y);
B(:,25)
runs without any error at all in R2020b.
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!