Lasso regression is a form of regression analysis used for variable selection and regularization. Use this tag for programming questions related to Lasso regression only. You can ask statistical questions on Cross Validated instead
Questions tagged [lasso-regression]
457 questions
20
votes
2 answers
Big matrix to run glmnet()
I am having a problem to run glmnet lasso with a wide data set. My data has N=50, but p > 49000, all factors. So to run glmnet i have to create a model.matrix, BUT i just run out of memory when i call model.matrix(formula, data), where formula =…

Flavio Barros
- 996
- 1
- 11
- 29
15
votes
3 answers
How to perform logistic lasso in python?
The scikit-learn package provides the functions Lasso() and LassoCV() but no option to fit a logistic function instead of a linear one...How to perform logistic lasso in python?

Fringant
- 525
- 1
- 5
- 17
14
votes
2 answers
Is LASSO regression implemented in Statsmodels?
I would love to use a linear LASSO regression within statsmodels, so to be able to use the 'formula' notation for writing the model, that would save me quite some coding time when working with many categorical variables, and their interactions.…

famargar
- 3,258
- 6
- 28
- 44
14
votes
4 answers
LASSO with $\lambda = 0$ and OLS produce different results in R glmnet
I expect LASSO with no penalization ($\lambda=0$) to yield the same (or very similar) coefficient estimates as an OLS fit. However, I get different coefficient estimates in R putting the same data (x,y) into
glmnet(x, y , alpha=1, lambda=0) for…
Helpa
12
votes
2 answers
Using LASSO in R with categorical variables
I've got a dataset with 1000 observations and 76 variables, about twenty of which are categorical. I want to use LASSO on this entire data set. I know that having factor variables doesn't really work in LASSO through either lars or glmnet, but the…

Alex
- 121
- 1
- 1
- 3
12
votes
1 answer
default lambda sequence in glmnet for cross-validation
Does anybody know how cv.glmnet (in R's glmnet) or LassoCV (scikit-learn) chooses a sequence of regularization constants (lambdas), which they use in cross-validation? Thank you very much!

user2575760
- 223
- 2
- 5
11
votes
2 answers
Lasso error in glmnet NA/NaN/Inf
I'm having an issue with glmnet in that I keep getting the error message
"Error in elnet(x, is.sparse, ix, jx, y, weights, offset, type.gaussian, : NA/NaN/Inf in foreign function call (arg 5)
In addition: Warning message:
In elnet(x, is.sparse,…

Jason
- 1,559
- 1
- 9
- 14
9
votes
5 answers
How does glmnet compute the maximal lambda value?
The glmnet package uses a range of LASSO tuning parameters lambda scaled from the maximal lambda_max under which no predictors are selected. I want to find out how glmnet computes this lambda_max value. For example, in a trivial…

Sacha Epskamp
- 46,463
- 20
- 113
- 131
7
votes
1 answer
How to use a lasso with the Vars package?
I'm trying to analyze a high dimensional data set (31 variables, 1100 observations) through a penalized vector autoregression.
Since I'm using the techniques introduced by Diebold et. al (2019) to build a network of connectedness through variance…

Manfretto
- 83
- 5
7
votes
3 answers
How to calculate R Squared value for Lasso regression using glmnet in R
I am performing lasso regression in R using glmnet package:
fit.lasso <- glmnet(x,y)
plot(fit.lasso,xvar="lambda",label=TRUE)
Then using cross-validation:
cv.lasso=cv.glmnet(x,y)
plot(cv.lasso)
One tutorial (last slide) suggest the following…

AKD
- 149
- 1
- 2
- 10
6
votes
2 answers
How to minimize lasso loss function with scipy.minimize?
Main issue: Why coefficients of Lasso regression are not shrunk to zero with minimization done by scipy.minimize?
I am trying to create Lasso model, using scipy.minimize. However, it is working only when alpha is zero (thus only like basic squared…

Jan Musil
- 508
- 5
- 15
6
votes
2 answers
Constructing fused lasso penalty with cvxpy package in python
Fused Lasso (Tibshirani et al, 2005) encourages sparsity of the coefficients and also sparsity of their differences.
This is the formula for the loss function and regularization:
The first term is the L2 (mse) loss, the second is an L1 penalty on…

Mine
- 831
- 1
- 8
- 27
6
votes
3 answers
Reproducing LASSO / Logistic Regression results in R with Python using the Iris Dataset
I'm trying to reproduce the following R results in Python. In this particular case the R predictive skill is lower than the Python skill, but this is usually not the case in my experience (hence the reason for wanting to reproduce the results in…

Oliver Angelil
- 1,099
- 15
- 31
6
votes
2 answers
How should I get the coefficients of Lasso Model?
Here is my code:
library(MASS)
library(caret)
df <- Boston
set.seed(3721)
cv.10.folds <- createFolds(df$medv, k = 10)
lasso_grid <- expand.grid(fraction=c(1,0.1,0.01,0.001))
lasso <- train(medv ~ .,
data = df,
…

KAICHENG WANG
- 61
- 1
- 4
6
votes
0 answers
Structure of the random effects in glmmLasso
I want to perform model selection among ~150 fixed-effect and 7 random-effect variables, on a set of 360 observations. I decided to use the Lasso procedure for mixed models, with the glmmLasso. I did a lost of researches to find some examples of…

T. Ravessoud
- 61
- 4