Is LASSO regression implemented in Statsmodels?
I would love to use LASSO linear regression in statsmodels to be able to use a "formula" formula to write the model, which would save me quite a bit of coding time when working with many categorical variables and their interactions. However, it looks like it hasn't been implemented in statistics models yet?
source to share
Lasso is really implemented in statsmodels. The documentation is in the url below:
To be precise, the implementation in statsmodel has both L1 and L2 regularizations, and their relative weight is specified by the L1_wt parameter. You should take a look at the formula below to make sure you are doing exactly what you want.
In addition to implementing the elastic network, statsmodels also implements the square root Lasso method.
source to share
You can use Patsy with scikit-learn to get the same results that you can get with formula notation in statsmodels. See the following code:
from patsy import dmatrices
# create dummy variables, and their interactions
y, X = dmatrices('outcome ~ C(var1)*C(var2)', df, return_type="dataframe")
# flatten y into a 1-D array so scikit-learn can understand it
y = np.ravel(y)
and now I can use any model implemented in scikit-learn with the usual notation having X as independent variables and y as dependent variables.
source to share