I'm wondering how to approach properly training and testing a LASSO model using glmnet in R?
- Specifically, I'm wondering how to do so if a lack of an external test data set necessitates I use cross-validation (or other similar approach) to test my LASSO model.
Let me break down my scenario:
I only have one data-set to inform and train my glmnet model. As a result, I'll have to use cross-validation to split up my data to also generate a way to test my model.
I'm already using cv.glmnet
, which according to the package details:
Does k-fold cross-validation for glmnet, produces a plot, and returns a value for lambda.
Is the cross-validation performed in
cv.glmnet
simply to pick the best lambda, or is it also serving as a more general cross-validation procedure?- In other words, do I still need to do another cross-validation step to "test" my model?
I'm working with the assumption that, "yes I do."
That being the case, how do I approach cross validating my cv.glmnet
model?
Do I have to do so manually, or is perhaps the
caret
function useful for glmnet models?Do I use two concentric "loops" of cross validation?... Do I use an "inner loop" of CV via
cv.glmnet
to determine the best lambda value within each of k folds of an "external loop" of k-fold cross validation processing?If I do cross-validation of my already cross-validating
cv.glmnet
model, how do I isolate the "best" model (from the "best" lambda value) from eachcv.glmnet
model within each fold of my otherwise "external loop" of cross validation?- Note: I'm defining "best" model as the model associated with a lambda that produces an MSE within 1 SE of the minimum ... this is the
$lambda.1se
in thecv.glmnet
model.
- Note: I'm defining "best" model as the model associated with a lambda that produces an MSE within 1 SE of the minimum ... this is the
Context:
I'm trying to predict tree age ("age") based on tree diameter ("D"), D^2, and species ("factor(SPEC)"). [resulting equation: Age ~ D + factor(SPEC) + D^2
]. I have ~50K rows of data, but the data is longitudinal (tracks individuals through time) and consists of ~65 species.