Questions tagged [glmnet]

glmnet is an R package for Lasso and elastic-net regularized generalized linear models.

Overview

glmnet is an R package which provides Lasso and elastic-net regularized generalized linear models. It features extremely efficient procedures for fitting the entire Lasso or elastic-net regularization path for linear regression, logistic and multinomial regression models, Poisson regression and the Cox model.

Resources

Tag usage

Questions on should be about implementation and programming problems, not about the statistical or theoretical properties of the technique.
Consider whether your question might be better suited to Cross Validated, the Stack Exchange site for statistics, machine learning and data analysis.

598 questions
13
votes
2 answers

executing cv.glmnet in parallel in R

My training dataset has about 200,000 records and I have 500 features. (These are sales data from a retail org). Most of the features are 0/1 and is stored as a sparse matrix. The goal is to predict the probability to buy for about 200 products.…
Rouse
  • 191
  • 1
  • 2
  • 5
12
votes
1 answer

Extract the coefficients for the best tuning parameters of a glmnet model in caret

I am running elastic net regularization in caret using glmnet. I pass sequence of values to trainControl for alpha and lambda, then I perform repeatedcv to get the optimal tunings of alpha and lambda. Here is an example where the optimal tunings for…
pd441
  • 2,644
  • 9
  • 30
  • 41
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

Automatic caret parameter tuning fails in glmnet

Context and error message I try to fit a two-class prediction model using glmnet within caret. I incur an error when using the caret default tune grids. I don't think it is due to wrongly formatted data because, when specifying my own tuning grid,…
workingonit
  • 113
  • 1
  • 10
11
votes
1 answer

glmnet: How do I know which factor level of my response is coded as 1 in logistic regression

I have a logistic regression model that I made using the glmnet package. My response variable was coded as a factor, the levels of which I will refer to as "a" and "b". The mathematics of logistic regression label one of the two classes as "0" and…
John Kleve
  • 499
  • 1
  • 4
  • 12
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
10
votes
3 answers

glmnet - variable importance?

I´m using the glmnet package to perform a LASSO regression. Is there a way to get the importance of the individual variables that were selected? I thought about ranking the coefficients that were obtained through the coef(...) command (i.e. the…
user86533
  • 323
  • 1
  • 7
  • 18
10
votes
2 answers

How to specify log link in glmnet?

I'm running an elastic net on a generalized linear model with the glmnet and caret packages in R. My response variable is cost (where cost > $0) and hence I'd like to specify a Gaussian family with a log link for my GLM. However glmnet doesn't seem…
RobertF
  • 824
  • 2
  • 14
  • 40
9
votes
2 answers

cv.glmnet fails for ridge, not lasso, for simulated data with coder error

Gist The error: Error in predmat[which, seq(nlami)] = preds : replacement has length zero The context: data is simulated with a binary y, but there are n coders of true y. the data is stacked n times and a model is fitted, trying to get true y. The…
Elad663
  • 783
  • 1
  • 5
  • 13
9
votes
7 answers

Predict function error for probabilities in glmnet?

I am trying to predict probabilities in a dataset using glmnet. My code reads: bank <- read.table("http://www.stat.columbia.edu/~madigan/W2025/data/BankSortedMissing.TXT",header=TRUE) bank$rich<-sample(c(0:1), 233, replace=TRUE) …
Kasia Danilczuk
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
9
votes
1 answer

Estimating many interaction terms in glmnet

It is my understanding that glmnet takes matrices where each column is an explanatory variable. I have a dataframe with ~10 explanatory variables (some of which are factors) How could I take a formula such as y~(x1*x2*x3)+(x4*x5)+x6 and estimate…
Will Beauchamp
  • 579
  • 2
  • 7
  • 18
8
votes
1 answer

S3 and order of classes

I've alway had trouble understanding the the documentation on how S3 methods are called, and this time it's biting me back. I'll apologize up front for asking more than one question, but they are all closely related. Deep in the heart of a complex…
Nick Sabbe
  • 11,684
  • 1
  • 43
  • 57
8
votes
2 answers

Columns not available for when training lasso model using caret

I am getting an odd error Error in `[.data.frame`(data, , lvls[1]) : undefined columns selected message when I am using caret to train a glmnet model. I have used basically the same code and the same predictors for an ordinal model (just with a…
Fredrik Karlsson
  • 485
  • 8
  • 21
1
2
3
39 40