I'm using sklearn's LogisticRegression with penaly=l1
(lasso regularization, as opposed to ridge regularization l2). Lasso is causing the optimization function to do implicit feature selection by setting some of the feature weights to zero (as opposed to ridge regularization, which will preserve all features with some non zero weight). Is it possible to extract this weight information (feature selection) from sklearn somehow?
1 Answer
Yes, as demonstrated in the documentation: http://scikit-learn.org/stable/auto_examples/linear_model/plot_logistic_path.html
Welcome to DataScience.SE
-
$\begingroup$ Thanks. So the magic attribute is
coef_
, called on the LogisticRegression object after fitting, eg.alg.coef_
. $\endgroup$ Sep 24, 2016 at 18:41