l0l2learn 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: l0l2learn
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Cardinality- and budget-constrained feature selection for logistic regression using mixed-integer conic optimization
|
|
5
|
+
Home-page: https://github.com/ml-lab-htw/l0l2learn
|
|
6
|
+
Author: Ricardo Knauer
|
|
7
|
+
Author-email: ricardo.knauer@htw-berlin.de
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: joblib
|
|
15
|
+
Requires-Dist: mosek
|
|
16
|
+
Requires-Dist: numpy
|
|
17
|
+
Requires-Dist: pandas
|
|
18
|
+
Requires-Dist: scikit-learn
|
|
19
|
+
Requires-Dist: scipy
|
|
20
|
+
Requires-Dist: tqdm
|
|
21
|
+
Dynamic: author
|
|
22
|
+
Dynamic: author-email
|
|
23
|
+
Dynamic: classifier
|
|
24
|
+
Dynamic: description
|
|
25
|
+
Dynamic: description-content-type
|
|
26
|
+
Dynamic: home-page
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
Dynamic: requires-dist
|
|
29
|
+
Dynamic: requires-python
|
|
30
|
+
Dynamic: summary
|
|
31
|
+
|
|
32
|
+
# l0l2learn
|
|
33
|
+
|
|
34
|
+
Feature selection for logistic regression using mixed-integer conic optimization. Unlike Lasso-based approaches, `l0l2learn` directly optimizes feature subsets under explicit cardinality or budget constraints.
|
|
35
|
+
|
|
36
|
+
## Overview
|
|
37
|
+
|
|
38
|
+
`l0l2learn` is a Python package that provides sklearn-style estimators for cardinality- and budget-constrained feature selection in logistic regression. The package currently includes:
|
|
39
|
+
|
|
40
|
+
- **L0L2Classifier**: L0-constrained L2-regularized logistic regression
|
|
41
|
+
- **ResampledL0L2Classifier**: resampling-based feature selection with frequency-based aggregation to improve the selection stability
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
To install the package, use the following command:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
pip install l0l2learn
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Please check the [MOSEK website](https://www.mosek.com/) to request and set up a license for the conic solver.
|
|
52
|
+
|
|
53
|
+
## Quick Start
|
|
54
|
+
|
|
55
|
+
### Feature Selection Without Resampling
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from sklearn.datasets import load_breast_cancer
|
|
59
|
+
from sklearn.metrics import roc_auc_score
|
|
60
|
+
from sklearn.model_selection import train_test_split
|
|
61
|
+
|
|
62
|
+
from l0l2learn import L0L2Classifier
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
X, y = load_breast_cancer(return_X_y=True, as_frame=True)
|
|
66
|
+
X_train, X_test, y_train, y_test = train_test_split(
|
|
67
|
+
X, y, stratify=y
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
clf = L0L2Classifier(
|
|
71
|
+
b=3,
|
|
72
|
+
lambd=1.0
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
clf.fit(X_train, y_train)
|
|
76
|
+
y_proba = clf.predict_proba(X_test)
|
|
77
|
+
|
|
78
|
+
print("ROC AUC: ", roc_auc_score(y_test, y_proba[:, 1]))
|
|
79
|
+
print("Coefficients: ", clf.coef_)
|
|
80
|
+
print("Intercept: ", clf.intercept_)
|
|
81
|
+
print("Support: ", clf.support_)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Feature Selection With Resampling
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from sklearn.datasets import load_breast_cancer
|
|
89
|
+
from sklearn.metrics import roc_auc_score
|
|
90
|
+
from sklearn.model_selection import train_test_split
|
|
91
|
+
|
|
92
|
+
from l0l2learn import ResampledL0L2Classifier
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
X, y = load_breast_cancer(return_X_y=True, as_frame=True)
|
|
96
|
+
X_train, X_test, y_train, y_test = train_test_split(
|
|
97
|
+
X, y, stratify=y
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
clf = ResampledL0L2Classifier(
|
|
101
|
+
b=3,
|
|
102
|
+
param_grid={"lambd": [1.0]},
|
|
103
|
+
n_resamples=3
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
clf.fit(X_train, y_train)
|
|
107
|
+
y_proba = clf.predict_proba(X_test)
|
|
108
|
+
|
|
109
|
+
print("ROC AUC: ", roc_auc_score(y_test, y_proba[:, 1]))
|
|
110
|
+
print("Coefficients: ", clf.coef_)
|
|
111
|
+
print("Intercept: ", clf.intercept_)
|
|
112
|
+
print("Support: ", clf.support_)
|
|
113
|
+
print("VIFs: ", clf.variable_inclusion_frequencies_[clf.support_])
|
|
114
|
+
print("MSFs: ", clf.model_selection_frequencies_)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Hyperparameters
|
|
118
|
+
|
|
119
|
+
### Feature Costs
|
|
120
|
+
|
|
121
|
+
Feature-specific costs can be supplied through `c`:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
clf = L0L2Classifier(c=[1, 2, 5])
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The optimization then accounts for some variables to be more expensive than others.
|
|
128
|
+
|
|
129
|
+
### Feature Selection Budget
|
|
130
|
+
|
|
131
|
+
The feature selection budget is controlled through `b`:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
clf = L0L2Classifier(b=5)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
When all feature costs are equal to one (the default), `b` directly controls the maximum number of selected features.
|
|
138
|
+
|
|
139
|
+
### L2 Regularization
|
|
140
|
+
|
|
141
|
+
The L2 regularization strength is given by `lambd`:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
clf = L0L2Classifier(lambd=0.1)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Larger values can attenuate overfitting and increase robustness.
|
|
148
|
+
|
|
149
|
+
### Number of Resamples
|
|
150
|
+
|
|
151
|
+
`n_resamples` determines how many resampled models are fitted:
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
clf = ResampledL0L2Classifier(b=5, n_resamples=99)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Larger values can improve frequency estimates but increase runtime.
|
|
158
|
+
|
|
159
|
+
### Other Hyperparameters
|
|
160
|
+
|
|
161
|
+
#### L0L2Classifier
|
|
162
|
+
|
|
163
|
+
- **`fit_intercept`**: Whether an intercept term is included in the logistic regression model.
|
|
164
|
+
|
|
165
|
+
- **`time_limit`**: Maximum runtime in seconds for the optimization problem.
|
|
166
|
+
|
|
167
|
+
- **`mosek_log`**: Enables printing of MOSEK solver output.
|
|
168
|
+
|
|
169
|
+
#### ResampledL0L2Classifier
|
|
170
|
+
|
|
171
|
+
- **`resampling`**: Controls whether and how rows, columns, both, or neither are resampled.
|
|
172
|
+
|
|
173
|
+
- **`n_row_subsamples`**: Number or fraction of observations used during row subsampling.
|
|
174
|
+
|
|
175
|
+
- **`n_column_subsamples`**: Number or fraction of features used during column subsampling.
|
|
176
|
+
|
|
177
|
+
- **`aggregation`**: Whether model selection or variable inclusion frequencies are used for aggregation.
|
|
178
|
+
|
|
179
|
+
- **`vif_threshold`**: Minimum variable inclusion frequency required when using `aggregation="VIF"`.
|
|
180
|
+
|
|
181
|
+
- **`estimator`**: Alternative base estimator used instead of the default `L0L2Classifier`.
|
|
182
|
+
|
|
183
|
+
- **`param_grid`**: Hyperparameter grid used for cross-validation when tuning `lambd`.
|
|
184
|
+
|
|
185
|
+
- **`cv`**: Cross-validation strategy used for hyperparameter tuning.
|
|
186
|
+
|
|
187
|
+
- **`scoring`**: Scoring metric used to select the best hyperparameter configuration.
|
|
188
|
+
|
|
189
|
+
- **`numerical_features`**: Specifies which DataFrame columns should be treated as numerical features.
|
|
190
|
+
|
|
191
|
+
- **`categorical_features`**: Specifies which DataFrame columns should be treated as categorical features.
|
|
192
|
+
|
|
193
|
+
- **`fit_intercept`**: Whether an intercept term is included in the logistic regression model.
|
|
194
|
+
|
|
195
|
+
- **`mosek_time_limit`**: Maximum runtime in seconds for each individual optimization problem.
|
|
196
|
+
|
|
197
|
+
- **`total_time_limit`**: Maximum runtime in seconds for the complete resampling procedure.
|
|
198
|
+
|
|
199
|
+
- **`max_consecutive_failures`**: Stops resampling if too many consecutive model fits fail.
|
|
200
|
+
|
|
201
|
+
- **`mosek_log`**: Enables printing of MOSEK solver output.
|
|
202
|
+
|
|
203
|
+
- **`n_jobs`**: Number of parallel workers used during resampling.
|
|
204
|
+
|
|
205
|
+
- **`random_state`**: Controls the randomness of resampling and cross-validation procedures.
|
|
206
|
+
|
|
207
|
+
## License
|
|
208
|
+
|
|
209
|
+
This project is licensed under the [MIT License](https://github.com/ml-lab-htw/l0l2learn/blob/main/LICENSE). See the `LICENSE` file for details.
|
|
210
|
+
|
|
211
|
+
## Authors
|
|
212
|
+
|
|
213
|
+
- Ricardo Knauer (HTW Berlin)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
l0l2learn-0.1.0.dist-info/licenses/LICENSE,sha256=XWqEg9JWIOhtrvRRAXc5PN6Zj2r0itYgxseLe1sO2rk,1066
|
|
2
|
+
l0l2learn-0.1.0.dist-info/METADATA,sha256=zK9RfWS3bP-BaKMJgzB4iyw95T0v1ebZLJyGjE9YaMk,6307
|
|
3
|
+
l0l2learn-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
4
|
+
l0l2learn-0.1.0.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
5
|
+
l0l2learn-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ml-lab-htw
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|