Skip to main content

featureranker

Tests PyPI

Ensemble feature ranking for any numeric feature matrix: tabular datasets, transformer embeddings, pooled hidden states, engineered features. Five methods rank every feature, a typed result object holds the evidence, and weighted rank voting produces one consensus ordering, for classification and regression. Unnamed matrices work directly: pass a numpy array and features get stable generated IDs.

Featured in:

Installation

pip install featureranker

Requires Python >= 3.11.

Quick start

from sklearn.datasets import load_breast_cancer
from featureranker import feature_ranking, voting, plot_rankings, plot_after_vote

cancer = load_breast_cancer(as_frame=True)
result = feature_ranking(cancer.data, cancer.target, task="classification")

vote_table = voting(result)                # ["feature", "score"], best first
plot_rankings(result, top_n=15)            # per-method ranks as a dot plot
plot_after_vote(vote_table, top_n=15)      # consensus scores

feature_ranking returns a RankingResult with per-method ranking tables, rank and score matrices, diagnostics, and save/load. Results are deterministic for a given random_state at any n_jobs.

Hugging Face datasets

Pass a Hub path, name the label column, list what to exclude; the rest become features. Categorical columns one-hot expand into named sub-features (sex-Female, workclass-Private) by default.

from featureranker import feature_ranking, get_hf_data

X, y = get_hf_data(
    "scikit-learn/adult-census-income",
    target="income",
    columns_to_drop=["fnlwgt"],
)
result = feature_ranking(X, y, task="classification")

One score from the best features

fit_convex finds the optimal convex combination of the top consensus features: weights >= 0 that sum to one, so each weight is that feature's share of a single interpretable scoring function.

fit = result.fit_convex(X, y, top_n=10)
fit.table()               # ["feature", "weight"], largest first
scores = fit.predict(X)   # rank rows by the combined score

Ranking methods

Key Method Score
rf Random forest Impurity importance from a halving-search-tuned forest
xg XGBoost Gain importance from a halving-search-tuned booster
mi Mutual information kNN-estimated dependency with the target
f_test ANOVA F-test Between/within variance ratio
l1 L1 regularization path Entry point on the lasso / L1 logistic path

Examples and the selection-vs-reduction study

20 datasets (transformer embeddings, classical NLP feature spaces, pixels, molecules, sensors) each run the same ablation: every ranking method and the ensemble vote as selectors against PCA, ICA, random projection, kernel PCA, Isomap, UMAP, and t-SNE at matched budgets, scored by linear, kNN, and SVM probes. Findings: the research report. Per-dataset pages live in docs/examples/, regenerated by the scripts in examples/; the ModernBERT sentiment deep dive walks the methodology on unnamed transformer dimensions.

Feature ranks by method on breast cancer

Documentation

Topic Page
Install and first run docs/quickstart.md
The math behind each method and the voting schemes docs/algorithms.md
Speed, the n_jobs core budget, determinism docs/performance.md
Every signature and exception docs/api.md
Upgrading from v2 docs/migration_v2_to_v3.md
Development and releases docs/contributing.md

The example notebook walks through classification and regression end to end.

Development

git clone https://github.com/lhallee/featureranker.git
cd featureranker
pip install -e ".[dev]"
pytest

Citation

@article{Hallee2023,
  title = {Machine learning classifiers predict key genomic and evolutionary traits across the kingdoms of life},
  volume = {13},
  ISSN = {2045-2322},
  url = {http://dx.doi.org/10.1038/s41598-023-28965-7},
  DOI = {10.1038/s41598-023-28965-7},
  number = {1},
  journal = {Scientific Reports},
  publisher = {Springer Science and Business Media LLC},
  author = {Hallee, Logan and Khomtchouk, Bohdan B.},
  year = {2023},
  month = feb
}
@article{Hallee2023cds,
  title = {cdsBERT - Extending Protein Language Models with Codon Awareness},
  url = {http://dx.doi.org/10.1101/2023.09.15.558027},
  DOI = {10.1101/2023.09.15.558027},
  publisher = {Cold Spring Harbor Laboratory},
  author = {Hallee, Logan and Rafailidis, Nikolaos and Gleghorn, Jason P.},
  year = {2023},
  month = sep
}

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

featureranker-3.0.4.tar.gz (6.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

featureranker-3.0.4-py3-none-any.whl (39.5 kB view details)

Uploaded Python 3

File details

Details for the file featureranker-3.0.4.tar.gz.

File metadata

  • Download URL: featureranker-3.0.4.tar.gz
  • Upload date:
  • Size: 6.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for featureranker-3.0.4.tar.gz
Algorithm Hash digest
SHA256 9f6b7e9c594d8dadaf76dfdc8ac3ecb127c3cb2e628d1361964cf28f659143c3
MD5 09d2f28e57b382553ead1ac311fa95d3
BLAKE2b-256 73844dd8a830ec357a37814e6174d248baea2cc77485660c7b66d7b9a9e066ae

See more details on using hashes here.

File details

Details for the file featureranker-3.0.4-py3-none-any.whl.

File metadata

  • Download URL: featureranker-3.0.4-py3-none-any.whl
  • Upload date:
  • Size: 39.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for featureranker-3.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f316de6a6cd598ea58c55b3f1a5d440c13bf3b4e11e1e562b6f12d90c624aa7e
MD5 0cbcdac9b2de5430070aa8625280f0d0
BLAKE2b-256 3eec03474af9215e5bccb12cba823feddb9d3285cc87939dfae8cae64cfa5988

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

3.0.4 This release

2 files

3.0.3

2 files

3.0.2

2 files

3.0.1

2 files

3.0.0

2 files

2.0.0

2 files

1.3.2

2 files

1.3.0

2 files

1.2.2

2 files

1.2.0

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.2

2 files

1.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page