2
$\begingroup$

I would love to use a linear LASSO regression within statsmodels, so to be able to use the 'formula' notation for writing the model, that would save me quite some coding time when working with many categorical variables, and their interactions. However, it seems like it is not implemented yet in stats models?

$\endgroup$
2
  • $\begingroup$ I haven't used statsmodel yet..but I do know that scikit learn has LASSO regression. Would that suit your purpose? $\endgroup$
    – Impuls3H
    Commented Apr 17, 2017 at 9:25
  • $\begingroup$ yes scikit-learn would do just as well, I just learnt how to use Patsy to use the 'formula' notation in sciki-learn $\endgroup$
    – famargar
    Commented Apr 17, 2017 at 9:44

3 Answers 3

4
$\begingroup$

The question-asker resorted to scikit-learn until now, but statsmodels has just come out with its implementation of Lasso regression. The docs here are pretty self-explanatory and concise.

$\endgroup$
1
$\begingroup$

Ok alternate solution: I can use Patsy with scikit-learn to obtain the same results I would obtain with the formula notation in statsmodels. See code below:

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 I can now use any model implemented in scikit-learn with the usual notations having X as independent variables, and y as dependent one.

$\endgroup$
0
$\begingroup$

http://statsmodels.sourceforge.net/stable/genindex.html

is the index page. "Lasso" is not found anywhere.

Why don't you use sckit-learn?

$\endgroup$
1
  • $\begingroup$ I am just now learning how to use LASSO in scikit-learn, and use patsy for the formula notation. Indeed it looks like it's not implemented in stats models. $\endgroup$
    – famargar
    Commented Apr 17, 2017 at 9:42

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.