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]
355 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
- 934
- 1
- 11
- 27
13
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
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,531
- 1
- 9
- 14
10
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
- 2,232
- 4
- 21
- 43
10
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
- 415
- 1
- 3
- 15
10
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
- 203
- 2
- 5
8
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
- 81
- 1
- 1
- 2
8
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
- 42,423
- 17
- 105
- 128
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
- 782
- 5
- 24
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
- 3
6
votes
2 answers
Lasso r code - what is wrong with it?
I am attempting to carry out lasso regression using the lars package but can not seem to get the lars bit to work. I have inputted code:
diabetes<-read.table("diabetes.txt", header=TRUE)
diabetes
library(lars)
diabetes.lasso = lars(diabetes$x,…
math11
- 507
- 2
- 6
- 8
5
votes
0 answers
Calculating the ridge parameter for given ridge estimates
Suppose response and covariate data are below:
(1.4, 0.0), (1.4, -2.0), (0.8, 0.0), (0.4,2.0).
I want to find the ridge parameter k, for which the ridge estimates are (1, -1/8) by applying the penalty parameter to slope.
Emma Johnsons
- 51
- 1
5
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
- 129
- 1
- 9
5
votes
1 answer
Why calculating MSE in lasso regression gives different outputs?
I am trying to run different regression models on the Prostate cancer data from the lasso2 package. When I use Lasso, I saw two different methods to calculate the mean square error. But they do give me quite different results, so I would want to…
chogall
- 75
- 2
- 5