Reputation: 1002
I fitted a LASSO logistic regression model using the caret package as follows,
require(ISLR)
require(caret)
mod_fitg <- train(Direction ~ Lag1 + Lag2 + Lag3 + Lag4 + Volume,
data=Smarket, method = "glmnet",
tuneGrid=expand.grid(
.alpha=1,
.lambda=(0.002)),
family="binomial")
coef(mod_fitg$finalModel, mod_fitg$bestTune$lambda)
6 x 1 sparse Matrix of class "dgCMatrix"
1
(Intercept) -0.088472239
Lag1 -0.065571845
Lag2 -0.035641733
Lag3 0.003564326
Lag4 0.001534829
Volume 0.110035397
The above coefficients are the standardized coefficients beacaue by defualt , the glmnet package standardize the coefficients. In this output, i want to know the meaning of the intercept term.
Because after the standardization , there should be no intercept term (As per the model coefficients using the same model using glmnet package)
y <- Smarket$Direction
x <- model.matrix(Direction ~ Lag1 + Lag2 + Lag3 + Lag4 + Volume, Smarket)[, -1]
lasso.mod <- glmnet(x,y, alpha = 1, lambda = 0.002,family='binomial')
lasso.mod$beta
5 x 1 sparse Matrix of class "dgCMatrix"
s0
Lag1 -0.065571799
Lag2 -0.035641706
Lag3 0.003564320
Lag4 0.001534812
Volume 0.110035335
Upvotes: 1
Views: 548
Reputation: 4284
Your two models are the same, it is just that in lasso.mod
the intercept coefficient is stored in lasso.mod$a0
.
lasso.mod$a0
# s0
# -0.08847216
Upvotes: 1