• Code
  • Dataset
  • Demo
  • Model

l0l2learn

Stable feature selection for logistic regression

A Python package with scikit-learn style classifiers that select a fixed number of features for logistic regression, optionally with resampling for more stable selections. It implements the methods of our paper in The International Journal of Biostatistics.

Interpretable clinical models need stable feature subsets: the selected predictors should not change much when the data changes slightly. With very few outcome events per variable, this is hard to achieve. l0l2learn selects feature subsets for logistic regression under an explicit cardinality or budget constraint, solved as a mixed-integer conic optimization problem, instead of relying on Lasso-style penalties.

It provides two estimators:

  • L0L2Classifier: L0-constrained, L2-regularized logistic regression
  • ResampledL0L2Classifier: the same with resampling and frequency-based aggregation for more stable selections, as proposed in our paper
from l0l2learn import ResampledL0L2Classifier

clf = ResampledL0L2Classifier(b=3, param_grid={"lambd": [1.0]}, n_resamples=3)
clf.fit(X_train, y_train)
clf.support_   # selected features

Install it with pip install l0l2learn. The conic solver needs a MOSEK license. The package is released under the MIT license.