6
$\begingroup$

I understand GLMnet standardizes the predictor variables by default before fitting the model.

After fitting, the computed regression coefficients are then destandardized to allow reporting in their natural metric as can be seen in the post here.

Is this the same for Caret using GLMnet? So if I get the coefficients for my final model for the best value of lambda by calling:

coef(mymodel$finalModel, mymodel$bestTune$lambda)

Are the coefficients related to standardized predictor variables or unstandarized predictor variables?

For example, say I am fitting an model using glmnet in caret for:

y = β0 + β1X1 + β2X2

and X1 is on a scale 0-1 but X2 is 1-100. To fit the model X1 and X2 would first be standardised to a mean of zero and a standard deviation of 1.

Would the reported coefficients β1 and β2 be for the standardised variables or for the unstandardized variables when using the Caret wrapper for GLMnet?

$\endgroup$

1 Answer 1

2
$\begingroup$

Caret will fit the final model using glmnet again, so it reports the coefficients in the same way as glmnet, which is in the scale of the original data:

library(mlbench)
library(caret)
library(glmnet)
data(BostonHousing)

mymodel = train(medv ~ .,data=BostonHousing,
method="glmnet",tuneLength=5,family="gaussian",
trControl=trainControl(method="cv",number=3))

coef(mymodel$finalModel, mymodel$bestTune$lambda)

                        1
(Intercept)  35.320709389
crim         -0.103881511
zn            0.043895667
indus         0.003208220
chas1         2.711134571
nox         -16.888148979
rm            3.839322105
age           .          
dis          -1.440898136
rad           0.276505032
tax          -0.010852819
ptratio      -0.938477290
b             0.009195566
lstat        -0.521371464

gmodel = glmnet(x=as.matrix(BostonHousing[,-14]),y=BostonHousing[,14],
lambda=mymodel$bestTune$lambda)

                   s0
crim     -0.098276800
zn        0.041402890
indus     .          
chas      2.680135523
nox     -16.309105862
rm        3.862803869
age       .          
dis      -1.395580453
rad       0.253522033
tax      -0.009853769
ptratio  -0.930332033
b         0.009020162
lstat    -0.522732773
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.