L1 and L2 Regularization for Polynomial Regression in R

by punit agrawal   Last Updated November 17, 2017 13:19 PM

So I having been using R to perform statistical analysis.

The 'lm' function is generally used to create a linear model, and this model can have degree 1 variables by using model= lm (y~ ., data= train)

Similarly degree 2 interaction can be done using model= lm(y~.*., data= train)

To apply regularization, the most preferred package seems to be glmnet, but glmnet can apply regularization only to the original dataset, and not to more complex polynomial models. Is there a way in R I can perform regularization to polynomial interaction terms of the original variables?

model.glmnet= glmnet(x= train[,1:4], y= train[,5], alpha=0)

P.S.- I do not wish to create those variables in the original dataset as that would be a very tedious task

Related Questions

How to interpret glmnet?

Updated April 06, 2017 15:19 PM

Simple question on plot from R's glmnet package

Updated June 03, 2016 08:08 AM

Warning: Phalcon\Cache\Backend\File::save(): Only 0 of 33085 bytes written, possibly out of free disk space in /home/queryxchang/public_html/public/index.php on line 37
Cache file /home/queryxchang/public_html/apps/frontend/config/../cache/-q-20-314253-l1-and-l2-regularization-for-polynomial-regression-in-r- could not be written