I would like to use GLM and Elastic Net to select those
relevant features + build a linear regression model (i.e., both
prediction and understanding, so it would be better to be left with
relatively few parameters). The output is continuous. It's
glmnet package, but I'm not 100% sure about the steps to follow:
UPDATE Based on "As previously noted, an object of class train contains an element called finalModel ,
which is the fitted model with the tuning parameter values selected by
resampling. This object can be used in the traditional way to generate
predictions for new samples, using that model's
predict function." Using caret to tune both alpha and lambda:
Does fitM replace previous step 2? If so, how to specify the glmnet options (type.gaussian="naive",lambda=cv$lambda.min/1se ) now?And the following predict step, can I replace model to fitM ?If I do
does it make sense at all or am I incorrectly mixing both package vocabulary? |
|||||
|
Part 1In the elastic net two types of constraints on the parameters are employed
One way to solve this is to treat cv.glmnet .The R package caret can build models using the glmnet package and should be set up to tune over both parameters Part 2Q3Yes, in this case where?glmnet suggests to use
Instead of storing all the inner-products computed along the way,
which can be inefficient with a large number of variables or when "naive" option will loop over If you had not specified this argument, glmnet would have chosen "naive" anyway as Q4Short answer, you don't need to specify a high value fornlambda now that you have chosen an optimal value, conditioned on nlambda at the default, unless it makes an appreciable difference in compute time.Q5This is a question about parsimony. Thelambda.min option refers to value of lambda.1se represents the value of lambda.min ), but which has error within 1 standard error of the best model. In other words, using the value of lambda.1se as the selected value for The choice is yours:
Part 3This is a simple one and is something you'll come across a lot with R. You use thepredict() function 99.9% of the time. R will arrange for the use of the correct function for the object supplied as the first argument.More technically, predict is a generic function, which has methods (versions of the function) for objects of different types (technically known as classes). The object created by glmnet has a particular class (or classes) depending on what type of model is actually fitted. glmnet (the package) provides methods for the predict
function for these different types of objects. R knows about these
methods and will choose the appropriate one based on the class of the
object supplied. |
|||||
|