pyensemblefs 0.3.13__tar.gz
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.
- pyensemblefs-0.3.13/LICENSE +21 -0
- pyensemblefs-0.3.13/PKG-INFO +293 -0
- pyensemblefs-0.3.13/README.md +227 -0
- pyensemblefs-0.3.13/pyproject.toml +63 -0
- pyensemblefs-0.3.13/setup.cfg +4 -0
- pyensemblefs-0.3.13/src/pyensemblefs/__init__.py +17 -0
- pyensemblefs-0.3.13/src/pyensemblefs/aggregators/__init__.py +99 -0
- pyensemblefs-0.3.13/src/pyensemblefs/aggregators/abcvote.py +270 -0
- pyensemblefs-0.3.13/src/pyensemblefs/aggregators/base.py +170 -0
- pyensemblefs-0.3.13/src/pyensemblefs/aggregators/rank.py +158 -0
- pyensemblefs-0.3.13/src/pyensemblefs/aggregators/score.py +219 -0
- pyensemblefs-0.3.13/src/pyensemblefs/aggregators/subset.py +310 -0
- pyensemblefs-0.3.13/src/pyensemblefs/api.py +212 -0
- pyensemblefs-0.3.13/src/pyensemblefs/cli.py +52 -0
- pyensemblefs-0.3.13/src/pyensemblefs/configs.py +33 -0
- pyensemblefs-0.3.13/src/pyensemblefs/datasets/__init__.py +13 -0
- pyensemblefs-0.3.13/src/pyensemblefs/datasets/breast_cancer.py +9 -0
- pyensemblefs-0.3.13/src/pyensemblefs/datasets/cancer.py +9 -0
- pyensemblefs-0.3.13/src/pyensemblefs/datasets/diabetes_sklearn.py +12 -0
- pyensemblefs-0.3.13/src/pyensemblefs/datasets/heart.py +13 -0
- pyensemblefs-0.3.13/src/pyensemblefs/datasets/pima.py +16 -0
- pyensemblefs-0.3.13/src/pyensemblefs/ensemble/__init__.py +0 -0
- pyensemblefs-0.3.13/src/pyensemblefs/ensemble/base.py +219 -0
- pyensemblefs-0.3.13/src/pyensemblefs/ensemble/bootstrapper.py +94 -0
- pyensemblefs-0.3.13/src/pyensemblefs/ensemble/featureselector.py +63 -0
- pyensemblefs-0.3.13/src/pyensemblefs/ensemble/metabootstrapper.py +256 -0
- pyensemblefs-0.3.13/src/pyensemblefs/estimators/base.py +116 -0
- pyensemblefs-0.3.13/src/pyensemblefs/estimators/evaluator.py +61 -0
- pyensemblefs-0.3.13/src/pyensemblefs/fsmethods/__init__.py +20 -0
- pyensemblefs-0.3.13/src/pyensemblefs/fsmethods/basefs.py +164 -0
- pyensemblefs-0.3.13/src/pyensemblefs/fsmethods/factory.py +146 -0
- pyensemblefs-0.3.13/src/pyensemblefs/fsmethods/rank.py +124 -0
- pyensemblefs-0.3.13/src/pyensemblefs/fsmethods/score.py +267 -0
- pyensemblefs-0.3.13/src/pyensemblefs/fsmethods/subset.py +308 -0
- pyensemblefs-0.3.13/src/pyensemblefs/fsmethods/variance.py +10 -0
- pyensemblefs-0.3.13/src/pyensemblefs/main.py +62 -0
- pyensemblefs-0.3.13/src/pyensemblefs/main_stab.py +173 -0
- pyensemblefs-0.3.13/src/pyensemblefs/pipeline.py +43 -0
- pyensemblefs-0.3.13/src/pyensemblefs/selectors/__init__.py +22 -0
- pyensemblefs-0.3.13/src/pyensemblefs/selectors/base.py +45 -0
- pyensemblefs-0.3.13/src/pyensemblefs/selectors/filters.py +111 -0
- pyensemblefs-0.3.13/src/pyensemblefs/selectors/model_based.py +118 -0
- pyensemblefs-0.3.13/src/pyensemblefs/stability/__init__.py +1 -0
- pyensemblefs-0.3.13/src/pyensemblefs/stability/base.py +26 -0
- pyensemblefs-0.3.13/src/pyensemblefs/stability/config.py +35 -0
- pyensemblefs-0.3.13/src/pyensemblefs/stability/evaluator.py +181 -0
- pyensemblefs-0.3.13/src/pyensemblefs/stability/expectations.py +62 -0
- pyensemblefs-0.3.13/src/pyensemblefs/stability/frequency.py +16 -0
- pyensemblefs-0.3.13/src/pyensemblefs/stability/helpers.py +120 -0
- pyensemblefs-0.3.13/src/pyensemblefs/stability/measures_adjusted_intersections.py +110 -0
- pyensemblefs-0.3.13/src/pyensemblefs/stability/measures_adjusted_other.py +122 -0
- pyensemblefs-0.3.13/src/pyensemblefs/stability/measures_unadjusted.py +175 -0
- pyensemblefs-0.3.13/src/pyensemblefs/stability/pairwise.py +21 -0
- pyensemblefs-0.3.13/src/pyensemblefs/stability/stability.py +283 -0
- pyensemblefs-0.3.13/src/pyensemblefs/stability/utils_io.py +48 -0
- pyensemblefs-0.3.13/src/pyensemblefs/tools/generate_feature_sets.py +131 -0
- pyensemblefs-0.3.13/src/pyensemblefs/tools/sim_matrix.py +86 -0
- pyensemblefs-0.3.13/src/pyensemblefs/utils/consts.py +13 -0
- pyensemblefs-0.3.13/src/pyensemblefs/utils/datasets.py +55 -0
- pyensemblefs-0.3.13/src/pyensemblefs/utils/loader.py +18 -0
- pyensemblefs-0.3.13/src/pyensemblefs/utils/plotter.py +24 -0
- pyensemblefs-0.3.13/src/pyensemblefs/viz/__init__.py +0 -0
- pyensemblefs-0.3.13/src/pyensemblefs/viz/comparison.py +134 -0
- pyensemblefs-0.3.13/src/pyensemblefs/viz/ranking.py +79 -0
- pyensemblefs-0.3.13/src/pyensemblefs/viz/stability.py +107 -0
- pyensemblefs-0.3.13/src/pyensemblefs/viz/visualizer.py +23 -0
- pyensemblefs-0.3.13/src/pyensemblefs.egg-info/PKG-INFO +293 -0
- pyensemblefs-0.3.13/src/pyensemblefs.egg-info/SOURCES.txt +71 -0
- pyensemblefs-0.3.13/src/pyensemblefs.egg-info/dependency_links.txt +1 -0
- pyensemblefs-0.3.13/src/pyensemblefs.egg-info/entry_points.txt +6 -0
- pyensemblefs-0.3.13/src/pyensemblefs.egg-info/requires.txt +29 -0
- pyensemblefs-0.3.13/src/pyensemblefs.egg-info/top_level.txt +1 -0
- pyensemblefs-0.3.13/tests/test_metabootstrapper_selectkbest.py +53 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
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,293 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyensemblefs
|
|
3
|
+
Version: 0.3.13
|
|
4
|
+
Summary: Ensemble feature selection with bootstrapping, heterogeneous selectors, and stability analysis.
|
|
5
|
+
Author: David Chushig-Muzo, Bryan Peralta-Arboleda, Eva Milara, Cristina Soguero-Ruiz
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/cdchushig/pyensemblefs.git
|
|
29
|
+
Project-URL: Issues, https://github.com/cdchushig
|
|
30
|
+
Keywords: feature selection,ensemble,stability,machine learning
|
|
31
|
+
Classifier: Programming Language :: Python :: 3
|
|
32
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Operating System :: OS Independent
|
|
35
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
36
|
+
Requires-Python: >=3.9
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
License-File: LICENSE
|
|
39
|
+
Requires-Dist: numpy>=1.23
|
|
40
|
+
Requires-Dist: pandas>=2.0
|
|
41
|
+
Requires-Dist: scikit-learn>=1.3
|
|
42
|
+
Requires-Dist: scipy>=1.10
|
|
43
|
+
Requires-Dist: networkx>=3.0
|
|
44
|
+
Requires-Dist: matplotlib>=3.7
|
|
45
|
+
Requires-Dist: seaborn>=0.13
|
|
46
|
+
Requires-Dist: upsetplot>=0.8
|
|
47
|
+
Requires-Dist: requests>=2.31
|
|
48
|
+
Requires-Dist: abcvoting>=2.0
|
|
49
|
+
Requires-Dist: coloredlogs>=15.0
|
|
50
|
+
Requires-Dist: tqdm>=4.66
|
|
51
|
+
Requires-Dist: joblib>=1.3
|
|
52
|
+
Requires-Dist: skrebate>=0.62
|
|
53
|
+
Provides-Extra: viz
|
|
54
|
+
Requires-Dist: matplotlib>=3.7; extra == "viz"
|
|
55
|
+
Requires-Dist: seaborn>=0.13; extra == "viz"
|
|
56
|
+
Requires-Dist: upsetplot>=0.8; extra == "viz"
|
|
57
|
+
Provides-Extra: relief
|
|
58
|
+
Requires-Dist: skrebate>=0.62; extra == "relief"
|
|
59
|
+
Provides-Extra: dev
|
|
60
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
61
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
62
|
+
Requires-Dist: mypy>=1.8; extra == "dev"
|
|
63
|
+
Requires-Dist: build>=1.2.1; extra == "dev"
|
|
64
|
+
Requires-Dist: twine>=5; extra == "dev"
|
|
65
|
+
Dynamic: license-file
|
|
66
|
+
|
|
67
|
+
pyensemblefs: a multi-threading Python library for ensemble feature selection.
|
|
68
|
+
====
|
|
69
|
+
|
|
70
|
+
This repository hosts **pyensemblefs**, a Python library for *ensemble feature selection*. Supports heterogeneous ensembles, bootstrapped evaluation, and stability analysis across feature selectors.<br>
|
|
71
|
+
It assists researchers in feature selection tasks without requiring significant programming effort.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Installation and setup
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install pyensemblefs
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
To download the source code, you can clone it from the GitHub repository:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
git clone git@github.com:cdchushig/pyensemblefs.git
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Requirements: Python ≥ 3.9, scikit-learn ≥ 1.2
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Library Highlights
|
|
92
|
+
|
|
93
|
+
**pyensemblefs** automatically extracts relevant features in datasets using bootstrapping and ensemble aggregation.
|
|
94
|
+
|
|
95
|
+
* **Intuitive, reproducible workflows:** compatible with scikit-learn pipelines.
|
|
96
|
+
* **Comprehensive documentation:** each feature selection and aggregation method is fully described.
|
|
97
|
+
* **Extensible architecture:** easily add custom selection or aggregation strategies.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Main Features
|
|
102
|
+
|
|
103
|
+
* **Bootstrap-based ensemble selection:** assess variability across resamples.
|
|
104
|
+
|
|
105
|
+
* **Heterogeneous ensembles:** combine different feature selectors (e.g., ANOVA, MI, Chi²).
|
|
106
|
+
|
|
107
|
+
* **Unified aggregator API:** aggregate results from scores, ranks, or binary supports.
|
|
108
|
+
|
|
109
|
+
* **Visualization tools:** plot selection frequency, consensus ranks, and stability matrices.
|
|
110
|
+
|
|
111
|
+
* **Stability metrics:** compute indices such as Kuncheva, Jaccard, or Spearman correlation.
|
|
112
|
+
|
|
113
|
+
* **Extensible design:** register custom selectors and aggregators via a single factory call.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Get started
|
|
118
|
+
|
|
119
|
+
Example using a built-in dataset and a simple configuration:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
import pyensemblefs
|
|
123
|
+
from pyensemblefs.datasets import load_pima_dataset
|
|
124
|
+
|
|
125
|
+
# Load dataset
|
|
126
|
+
df = load_pima_dataset()
|
|
127
|
+
|
|
128
|
+
# Retrieve a pre-defined configuration (e.g., Relief filter)
|
|
129
|
+
cfg = pyensemblefs.get_config('relief', n_bootrap=100, fnc_aggregation='voting')
|
|
130
|
+
|
|
131
|
+
# Compute feature scores
|
|
132
|
+
df_feature_scores = pyensemblefs.compute_scores(cfg, df)
|
|
133
|
+
|
|
134
|
+
# Extract the most relevant features
|
|
135
|
+
df_filtered = pyensemblefs.extract_features(n_max_features=10)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Heterogeneous ensemble feature selection
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from sklearn.datasets import load_breast_cancer
|
|
144
|
+
from sklearn.feature_selection import SelectKBest, f_classif, mutual_info_classif, chi2
|
|
145
|
+
from pyensemblefs.ensemble.metabootstrapper import MetaBootstrapper
|
|
146
|
+
|
|
147
|
+
X, y = load_breast_cancer(return_X_y=True)
|
|
148
|
+
|
|
149
|
+
fs_methods = [
|
|
150
|
+
SelectKBest(score_func=f_classif, k=10),
|
|
151
|
+
SelectKBest(score_func=mutual_info_classif, k=10),
|
|
152
|
+
SelectKBest(score_func=chi2, k=10),
|
|
153
|
+
]
|
|
154
|
+
|
|
155
|
+
# Assign higher weight to ANOVA
|
|
156
|
+
weights = {"SelectKBest": 2.0}
|
|
157
|
+
|
|
158
|
+
boot = MetaBootstrapper(
|
|
159
|
+
fs_methods,
|
|
160
|
+
n_bootstraps=20,
|
|
161
|
+
n_jobs=4,
|
|
162
|
+
random_state=42,
|
|
163
|
+
strategy="random",
|
|
164
|
+
normalize_scores=True,
|
|
165
|
+
method_weights=weights,
|
|
166
|
+
verbose=True
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
boot.fit(X, y)
|
|
170
|
+
|
|
171
|
+
print("First bootstrap method:", boot.results_[0]["method"])
|
|
172
|
+
print("Normalized + weighted scores:", boot.results_[0]["scores"][:10])
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Visualization of frequency, top-k, and stability
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
from sklearn.datasets import load_breast_cancer
|
|
181
|
+
from sklearn.feature_selection import SelectKBest, mutual_info_classif
|
|
182
|
+
from pyensemblefs.ensemble.bootstrapper import Bootstrapper
|
|
183
|
+
from pyensemblefs.aggregators.rank import MeanRankAggregator
|
|
184
|
+
from pyensemblefs.aggregators.score import MeanAggregator
|
|
185
|
+
from pyensemblefs.viz.visualizer import Visualizer
|
|
186
|
+
|
|
187
|
+
X, y = load_breast_cancer(return_X_y=True)
|
|
188
|
+
fs = SelectKBest(score_func=mutual_info_classif, k=10)
|
|
189
|
+
boot = Bootstrapper(fs, n_bootstraps=25, n_jobs=2)
|
|
190
|
+
boot.fit(X, y)
|
|
191
|
+
|
|
192
|
+
# Aggregators
|
|
193
|
+
rank_agg = MeanRankAggregator(top_k=10).fit(boot.results_)
|
|
194
|
+
mean_agg = MeanAggregator(top_k=10).fit(boot.results_)
|
|
195
|
+
|
|
196
|
+
# Visualizations
|
|
197
|
+
Visualizer.feature_frequency(boot.results_, n_features=X.shape[1], top_k=15)
|
|
198
|
+
Visualizer.consensus_ranking(rank_agg.final_ranking_, top_k=10)
|
|
199
|
+
Visualizer.stability_heatmap(boot.results_, n_features=X.shape[1])
|
|
200
|
+
Visualizer.compare_aggregators({
|
|
201
|
+
"RankAggregator": rank_agg.final_ranking_,
|
|
202
|
+
"MeanAggregator": mean_agg.final_ranking_,
|
|
203
|
+
}, top_k=10)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
All figures are automatically saved under ./images/.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Stability Metrics
|
|
211
|
+
|
|
212
|
+
Stability analysis quantifies how consistent the selected features remain across bootstrap samples.
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from pyensemblefs.stats.stability import StabilityEvaluator
|
|
216
|
+
|
|
217
|
+
stab = StabilityEvaluator(metric="kuncheva")
|
|
218
|
+
stability_score = stab.compute(boot.results_binary_)
|
|
219
|
+
print("Stability (Kuncheva):", stability_score)
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Available metrics include Jaccard,Dice, Ochiai, Hamming, Novovicova, Davis, Lustgartn, Phi, Kappa, Nogueira, Yu, and Zucknick.
|
|
223
|
+
They can be directly compared between homogeneous and heterogeneous ensembles.
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Usage examples (scikit-learn compatible)
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
from sklearn.datasets import load_breast_cancer
|
|
232
|
+
from sklearn.feature_selection import SelectKBest, f_classif
|
|
233
|
+
from src.ensemble.bootstrapper import Bootstrapper
|
|
234
|
+
from src.aggregators.score import MeanAggregator
|
|
235
|
+
from src.aggregators.rank import MeanRankAggregator
|
|
236
|
+
|
|
237
|
+
X, y = load_breast_cancer(return_X_y=True)
|
|
238
|
+
|
|
239
|
+
fs = SelectKBest(score_func=f_classif, k=10)
|
|
240
|
+
boot = Bootstrapper(fs, n_bootstraps=30, n_jobs=4, random_state=42)
|
|
241
|
+
boot.fit(X, y)
|
|
242
|
+
|
|
243
|
+
# Aggregate scores and ranks
|
|
244
|
+
mean_agg = MeanAggregator().fit(boot.results_)
|
|
245
|
+
rank_agg = MeanRankAggregator().fit(boot.results_)
|
|
246
|
+
|
|
247
|
+
print("Consensus scores:", mean_agg.scores_[:10])
|
|
248
|
+
print("Consensus ranks:", rank_agg.rank_[:10])
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
from sklearn.feature_selection import SelectKBest, chi2
|
|
253
|
+
from src.ensemble.bootstrapper import Bootstrapper
|
|
254
|
+
from src.aggregators.score import MeanAggregator
|
|
255
|
+
|
|
256
|
+
fs = SelectKBest(score_func=chi2, k=5)
|
|
257
|
+
boot = Bootstrapper(fs, n_bootstraps=15, n_jobs=2)
|
|
258
|
+
boot.fit(X, y)
|
|
259
|
+
|
|
260
|
+
mean_agg = MeanAggregator().fit(boot.results_)
|
|
261
|
+
print("Consensus Scores (Chi2):", mean_agg.scores_)
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## How It Fits Together
|
|
267
|
+
|
|
268
|
+
Data → Bootstrapper / MetaBootstrapper<br>
|
|
269
|
+
↓<br>
|
|
270
|
+
Aggregators (Score / Rank / Subset)<br>
|
|
271
|
+
↓<br>
|
|
272
|
+
Visualizer / StabilityEvaluator → Reports
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Citation
|
|
277
|
+
|
|
278
|
+
If you use pyensemblefs in academic work, please cite:
|
|
279
|
+
|
|
280
|
+
@software{pyensemblefs2025,<br>
|
|
281
|
+
author = {Chushig-Muzo, C.D. and collaborators},<br>
|
|
282
|
+
title = {pyensemblefs: Ensemble Feature Selection Library},<br>
|
|
283
|
+
year = {2025},<br>
|
|
284
|
+
url = {https://github.com/cdchushig/pyensemblefs}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## License
|
|
291
|
+
|
|
292
|
+
This project is licensed under the MIT License – see the [LICENSE](LICENSE) file for details.
|
|
293
|
+
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
pyensemblefs: a multi-threading Python library for ensemble feature selection.
|
|
2
|
+
====
|
|
3
|
+
|
|
4
|
+
This repository hosts **pyensemblefs**, a Python library for *ensemble feature selection*. Supports heterogeneous ensembles, bootstrapped evaluation, and stability analysis across feature selectors.<br>
|
|
5
|
+
It assists researchers in feature selection tasks without requiring significant programming effort.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation and setup
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install pyensemblefs
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
To download the source code, you can clone it from the GitHub repository:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
git clone git@github.com:cdchushig/pyensemblefs.git
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requirements: Python ≥ 3.9, scikit-learn ≥ 1.2
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Library Highlights
|
|
26
|
+
|
|
27
|
+
**pyensemblefs** automatically extracts relevant features in datasets using bootstrapping and ensemble aggregation.
|
|
28
|
+
|
|
29
|
+
* **Intuitive, reproducible workflows:** compatible with scikit-learn pipelines.
|
|
30
|
+
* **Comprehensive documentation:** each feature selection and aggregation method is fully described.
|
|
31
|
+
* **Extensible architecture:** easily add custom selection or aggregation strategies.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Main Features
|
|
36
|
+
|
|
37
|
+
* **Bootstrap-based ensemble selection:** assess variability across resamples.
|
|
38
|
+
|
|
39
|
+
* **Heterogeneous ensembles:** combine different feature selectors (e.g., ANOVA, MI, Chi²).
|
|
40
|
+
|
|
41
|
+
* **Unified aggregator API:** aggregate results from scores, ranks, or binary supports.
|
|
42
|
+
|
|
43
|
+
* **Visualization tools:** plot selection frequency, consensus ranks, and stability matrices.
|
|
44
|
+
|
|
45
|
+
* **Stability metrics:** compute indices such as Kuncheva, Jaccard, or Spearman correlation.
|
|
46
|
+
|
|
47
|
+
* **Extensible design:** register custom selectors and aggregators via a single factory call.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Get started
|
|
52
|
+
|
|
53
|
+
Example using a built-in dataset and a simple configuration:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import pyensemblefs
|
|
57
|
+
from pyensemblefs.datasets import load_pima_dataset
|
|
58
|
+
|
|
59
|
+
# Load dataset
|
|
60
|
+
df = load_pima_dataset()
|
|
61
|
+
|
|
62
|
+
# Retrieve a pre-defined configuration (e.g., Relief filter)
|
|
63
|
+
cfg = pyensemblefs.get_config('relief', n_bootrap=100, fnc_aggregation='voting')
|
|
64
|
+
|
|
65
|
+
# Compute feature scores
|
|
66
|
+
df_feature_scores = pyensemblefs.compute_scores(cfg, df)
|
|
67
|
+
|
|
68
|
+
# Extract the most relevant features
|
|
69
|
+
df_filtered = pyensemblefs.extract_features(n_max_features=10)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Heterogeneous ensemble feature selection
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from sklearn.datasets import load_breast_cancer
|
|
78
|
+
from sklearn.feature_selection import SelectKBest, f_classif, mutual_info_classif, chi2
|
|
79
|
+
from pyensemblefs.ensemble.metabootstrapper import MetaBootstrapper
|
|
80
|
+
|
|
81
|
+
X, y = load_breast_cancer(return_X_y=True)
|
|
82
|
+
|
|
83
|
+
fs_methods = [
|
|
84
|
+
SelectKBest(score_func=f_classif, k=10),
|
|
85
|
+
SelectKBest(score_func=mutual_info_classif, k=10),
|
|
86
|
+
SelectKBest(score_func=chi2, k=10),
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
# Assign higher weight to ANOVA
|
|
90
|
+
weights = {"SelectKBest": 2.0}
|
|
91
|
+
|
|
92
|
+
boot = MetaBootstrapper(
|
|
93
|
+
fs_methods,
|
|
94
|
+
n_bootstraps=20,
|
|
95
|
+
n_jobs=4,
|
|
96
|
+
random_state=42,
|
|
97
|
+
strategy="random",
|
|
98
|
+
normalize_scores=True,
|
|
99
|
+
method_weights=weights,
|
|
100
|
+
verbose=True
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
boot.fit(X, y)
|
|
104
|
+
|
|
105
|
+
print("First bootstrap method:", boot.results_[0]["method"])
|
|
106
|
+
print("Normalized + weighted scores:", boot.results_[0]["scores"][:10])
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Visualization of frequency, top-k, and stability
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from sklearn.datasets import load_breast_cancer
|
|
115
|
+
from sklearn.feature_selection import SelectKBest, mutual_info_classif
|
|
116
|
+
from pyensemblefs.ensemble.bootstrapper import Bootstrapper
|
|
117
|
+
from pyensemblefs.aggregators.rank import MeanRankAggregator
|
|
118
|
+
from pyensemblefs.aggregators.score import MeanAggregator
|
|
119
|
+
from pyensemblefs.viz.visualizer import Visualizer
|
|
120
|
+
|
|
121
|
+
X, y = load_breast_cancer(return_X_y=True)
|
|
122
|
+
fs = SelectKBest(score_func=mutual_info_classif, k=10)
|
|
123
|
+
boot = Bootstrapper(fs, n_bootstraps=25, n_jobs=2)
|
|
124
|
+
boot.fit(X, y)
|
|
125
|
+
|
|
126
|
+
# Aggregators
|
|
127
|
+
rank_agg = MeanRankAggregator(top_k=10).fit(boot.results_)
|
|
128
|
+
mean_agg = MeanAggregator(top_k=10).fit(boot.results_)
|
|
129
|
+
|
|
130
|
+
# Visualizations
|
|
131
|
+
Visualizer.feature_frequency(boot.results_, n_features=X.shape[1], top_k=15)
|
|
132
|
+
Visualizer.consensus_ranking(rank_agg.final_ranking_, top_k=10)
|
|
133
|
+
Visualizer.stability_heatmap(boot.results_, n_features=X.shape[1])
|
|
134
|
+
Visualizer.compare_aggregators({
|
|
135
|
+
"RankAggregator": rank_agg.final_ranking_,
|
|
136
|
+
"MeanAggregator": mean_agg.final_ranking_,
|
|
137
|
+
}, top_k=10)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
All figures are automatically saved under ./images/.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Stability Metrics
|
|
145
|
+
|
|
146
|
+
Stability analysis quantifies how consistent the selected features remain across bootstrap samples.
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from pyensemblefs.stats.stability import StabilityEvaluator
|
|
150
|
+
|
|
151
|
+
stab = StabilityEvaluator(metric="kuncheva")
|
|
152
|
+
stability_score = stab.compute(boot.results_binary_)
|
|
153
|
+
print("Stability (Kuncheva):", stability_score)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Available metrics include Jaccard,Dice, Ochiai, Hamming, Novovicova, Davis, Lustgartn, Phi, Kappa, Nogueira, Yu, and Zucknick.
|
|
157
|
+
They can be directly compared between homogeneous and heterogeneous ensembles.
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Usage examples (scikit-learn compatible)
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from sklearn.datasets import load_breast_cancer
|
|
166
|
+
from sklearn.feature_selection import SelectKBest, f_classif
|
|
167
|
+
from src.ensemble.bootstrapper import Bootstrapper
|
|
168
|
+
from src.aggregators.score import MeanAggregator
|
|
169
|
+
from src.aggregators.rank import MeanRankAggregator
|
|
170
|
+
|
|
171
|
+
X, y = load_breast_cancer(return_X_y=True)
|
|
172
|
+
|
|
173
|
+
fs = SelectKBest(score_func=f_classif, k=10)
|
|
174
|
+
boot = Bootstrapper(fs, n_bootstraps=30, n_jobs=4, random_state=42)
|
|
175
|
+
boot.fit(X, y)
|
|
176
|
+
|
|
177
|
+
# Aggregate scores and ranks
|
|
178
|
+
mean_agg = MeanAggregator().fit(boot.results_)
|
|
179
|
+
rank_agg = MeanRankAggregator().fit(boot.results_)
|
|
180
|
+
|
|
181
|
+
print("Consensus scores:", mean_agg.scores_[:10])
|
|
182
|
+
print("Consensus ranks:", rank_agg.rank_[:10])
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
from sklearn.feature_selection import SelectKBest, chi2
|
|
187
|
+
from src.ensemble.bootstrapper import Bootstrapper
|
|
188
|
+
from src.aggregators.score import MeanAggregator
|
|
189
|
+
|
|
190
|
+
fs = SelectKBest(score_func=chi2, k=5)
|
|
191
|
+
boot = Bootstrapper(fs, n_bootstraps=15, n_jobs=2)
|
|
192
|
+
boot.fit(X, y)
|
|
193
|
+
|
|
194
|
+
mean_agg = MeanAggregator().fit(boot.results_)
|
|
195
|
+
print("Consensus Scores (Chi2):", mean_agg.scores_)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## How It Fits Together
|
|
201
|
+
|
|
202
|
+
Data → Bootstrapper / MetaBootstrapper<br>
|
|
203
|
+
↓<br>
|
|
204
|
+
Aggregators (Score / Rank / Subset)<br>
|
|
205
|
+
↓<br>
|
|
206
|
+
Visualizer / StabilityEvaluator → Reports
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Citation
|
|
211
|
+
|
|
212
|
+
If you use pyensemblefs in academic work, please cite:
|
|
213
|
+
|
|
214
|
+
@software{pyensemblefs2025,<br>
|
|
215
|
+
author = {Chushig-Muzo, C.D. and collaborators},<br>
|
|
216
|
+
title = {pyensemblefs: Ensemble Feature Selection Library},<br>
|
|
217
|
+
year = {2025},<br>
|
|
218
|
+
url = {https://github.com/cdchushig/pyensemblefs}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
This project is licensed under the MIT License – see the [LICENSE](LICENSE) file for details.
|
|
227
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pyensemblefs"
|
|
7
|
+
version = "0.3.13"
|
|
8
|
+
description = "Ensemble feature selection with bootstrapping, heterogeneous selectors, and stability analysis."
|
|
9
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
authors = [{ name = "David Chushig-Muzo" },
|
|
13
|
+
{ name = "Bryan Peralta-Arboleda" },
|
|
14
|
+
{ name = "Eva Milara" },
|
|
15
|
+
{ name = "Cristina Soguero-Ruiz" }]
|
|
16
|
+
keywords = ["feature selection", "ensemble", "stability", "machine learning"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
dependencies = [
|
|
26
|
+
"numpy>=1.23",
|
|
27
|
+
"pandas>=2.0",
|
|
28
|
+
"scikit-learn>=1.3",
|
|
29
|
+
"scipy>=1.10",
|
|
30
|
+
"networkx>=3.0",
|
|
31
|
+
"matplotlib>=3.7",
|
|
32
|
+
"seaborn>=0.13",
|
|
33
|
+
"upsetplot>=0.8",
|
|
34
|
+
"requests>=2.31",
|
|
35
|
+
"abcvoting>=2.0",
|
|
36
|
+
"coloredlogs>=15.0",
|
|
37
|
+
"tqdm>=4.66",
|
|
38
|
+
"joblib>=1.3",
|
|
39
|
+
"skrebate>=0.62"
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.optional-dependencies]
|
|
43
|
+
viz = ["matplotlib>=3.7", "seaborn>=0.13", "upsetplot>=0.8"]
|
|
44
|
+
relief = ["skrebate>=0.62"]
|
|
45
|
+
dev = ["pytest>=7", "ruff>=0.4", "mypy>=1.8", "build>=1.2.1", "twine>=5"]
|
|
46
|
+
|
|
47
|
+
[project.urls]
|
|
48
|
+
Homepage = "https://github.com/cdchushig/pyensemblefs.git"
|
|
49
|
+
Issues = "https://github.com/cdchushig"
|
|
50
|
+
|
|
51
|
+
[tool.setuptools.packages.find]
|
|
52
|
+
where = ["src"]
|
|
53
|
+
include = ["pyensemblefs*"]
|
|
54
|
+
|
|
55
|
+
[tool.setuptools.package-data]
|
|
56
|
+
pyensemblefs = ["py.typed"]
|
|
57
|
+
|
|
58
|
+
[project.scripts]
|
|
59
|
+
pyefs = "pyensemblefs.cli:main"
|
|
60
|
+
pyefs-stab = "pyensemblefs.main_stab:main"
|
|
61
|
+
pyefs-pipeline = "pyensemblefs.pipeline:main"
|
|
62
|
+
pyefs-gen = "pyensemblefs.tools.generate_feature_sets:main"
|
|
63
|
+
pyefs-sim = "pyensemblefs.tools.sim_matrix:main"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
3
|
+
|
|
4
|
+
from . import datasets
|
|
5
|
+
from .api import get_config, compute_scores, extract_features
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"aggregators","ensemble","estimators","fsmethods","selectors",
|
|
9
|
+
"stability","tools","utils","viz",
|
|
10
|
+
"datasets","get_config","compute_scores","extract_features"
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
def _get_version() -> str:
|
|
14
|
+
try: return version("pyensemblefs")
|
|
15
|
+
except PackageNotFoundError: return "0.0.0"
|
|
16
|
+
|
|
17
|
+
__version__ = _get_version()
|