Skip to main content

ranking-feature-selector

ranking-feature-selector is a leakage-safe, nested-CV feature selection package for small tabular data. It supports binary classification, single-output regression, and right-censored survival analysis.

It is designed for research workflows where feature ranking, feature-count selection, preprocessing, and performance estimation should be performed inside cross-validation folds to reduce data leakage.

Installation

pip install ranking-feature-selector

For survival analysis / Random Survival Forests:

pip install "ranking-feature-selector[survival]"

For SHAP-based ranking backends:

pip install "ranking-feature-selector[shap]"

For imbalanced-learn samplers in binary classification:

pip install "ranking-feature-selector[imbalance]"

For all optional backends:

pip install "ranking-feature-selector[all]"

Quick start

from ranking_feature_selector import RobustSurvivalFeatureSelectorCV

selector = RobustSurvivalFeatureSelectorCV(
    model=rsf,
    max_features=20,
    preset="safe",
    preprocessor="standardize",
    random_state=42,
)
selector.fit(X, y, groups=center_id)
print(selector.selected_features_)
print(selector.summary())

For most use cases, start with a task-specific class, model, max_features, preset, preprocessor, and random_state. Advanced controls are grouped under cv_config, selection_config, and importance_config.

Main classes

from ranking_feature_selector import (
    RobustClassificationFeatureSelectorCV,
    RobustRegressionFeatureSelectorCV,
    RobustSurvivalFeatureSelectorCV,
)
Class Task Required model API
RobustClassificationFeatureSelectorCV Binary classification fit(X, y) and predict_proba(X)
RobustRegressionFeatureSelectorCV Regression fit(X, y) and predict(X)
RobustSurvivalFeatureSelectorCV Right-censored survival analysis fit(X, y) and a risk-score interface, usually predict(X)

RobustFeatureSelectorCV(task=...) is also available as a generic interface. RobustShapFeatureSelectorCV is kept as a backward-compatible class alias.

Backward-compatible import aliases are also provided:

from robust_feature_selector import RobustSurvivalFeatureSelectorCV
from robust_shap_selector import RobustSurvivalFeatureSelectorCV

New code should prefer:

from ranking_feature_selector import RobustSurvivalFeatureSelectorCV

What the package does

For each outer CV fold, the selector performs feature ranking and feature-count selection using only the training portion of that fold:

  1. Fit preprocessing on the training fold only.
  2. Rank features inside inner-CV training folds.
  3. Select the number of features using inner-CV performance.
  4. Refit on the outer-training fold using the selected features.
  5. Evaluate on the untouched outer-test fold.
  6. Aggregate fold-wise selections into selected_features_ using selection frequency.

This means that the reported outer-CV performance reflects fold-specific selected feature sets. The final selected_features_ list is a stability-based summary across outer folds.

Presets

Preset Intended use Behavior
"fast" Initial checks Fewer repeats and smaller CV
"safe" Default research use Nested CV, one-standard-error rule, shadow features enabled
"publication" More conservative analysis More repeats and stricter stability threshold
"custom" Full control Override settings via config dictionaries

Preprocessing and standardization

preprocessor must preserve the same number and order of columns. One-hot encoding, target encoding, PCA, or other feature-expanding transformations should be performed before calling the selector.

Setting Behavior
preprocessor="auto" Median imputation
preprocessor="median_impute" Median imputation
preprocessor="standardize" Median imputation + StandardScaler
preprocessor="none" No preprocessing
standardize=True Adds StandardScaler after median imputation when using "auto"
custom transformer Any same-column sklearn-compatible transformer

Example:

selector = RobustRegressionFeatureSelectorCV(
    model=model,
    max_features=15,
    preprocessor="standardize",
)

Custom preprocessing:

from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import RobustScaler

preprocessor = Pipeline([
    ("imputer", SimpleImputer(strategy="median")),
    ("scaler", RobustScaler()),
])

selector = RobustRegressionFeatureSelectorCV(
    model=model,
    max_features=15,
    preprocessor=preprocessor,
)

Supported models

model should be a scikit-learn compatible estimator that can be cloned with sklearn.base.clone().

Binary classification

Required API:

model.fit(X_train, y_train)
model.predict_proba(X_valid)

Recommended models include:

  • sklearn.ensemble.RandomForestClassifier
  • sklearn.ensemble.ExtraTreesClassifier
  • sklearn.linear_model.LogisticRegression
  • lightgbm.LGBMClassifier
  • xgboost.XGBClassifier
  • catboost.CatBoostClassifier
  • sklearn.svm.SVC(probability=True)

Classification samplers such as SMOTE can be passed only to RobustClassificationFeatureSelectorCV:

from imblearn.over_sampling import SMOTE
from ranking_feature_selector import RobustClassificationFeatureSelectorCV

selector = RobustClassificationFeatureSelectorCV(
    model=model,
    max_features=20,
    sampler=SMOTE(random_state=42),
    preset="safe",
)

Regression

Required API:

model.fit(X_train, y_train)
model.predict(X_valid)

Recommended models include:

  • sklearn.ensemble.RandomForestRegressor
  • sklearn.ensemble.ExtraTreesRegressor
  • sklearn.linear_model.ElasticNet, Ridge, Lasso
  • lightgbm.LGBMRegressor
  • xgboost.XGBRegressor
  • catboost.CatBoostRegressor
  • SVR or KNeighborsRegressor with importance_config={"method": "permutation"}

Survival analysis

Required API:

model.fit(X_train, y_train)
risk_score = model.predict(X_valid)

Recommended models include:

  • sksurv.ensemble.RandomSurvivalForest
  • sksurv.linear_model.CoxPHSurvivalAnalysis
  • sksurv.ensemble.GradientBoostingSurvivalAnalysis
  • sksurv.ensemble.ComponentwiseGradientBoostingSurvivalAnalysis

y can be a sksurv.util.Surv.from_arrays(event, time) structured array, an (event, time) tuple, a two-column array, or a DataFrame with event/time columns.

from sksurv.util import Surv

y = Surv.from_arrays(event=event, time=time)

Survival risk-score configuration

By default, RobustSurvivalFeatureSelectorCV uses model.predict(X) as the risk score for C-index and permutation importance. Larger values are assumed to mean higher event risk.

Setting Meaning Required model API
risk_score="predict" Uses model.predict(X) predict(X)
risk_score="event_probability" Uses `1 - S(t X)atprediction_time`
risk_score="cumulative_hazard" Uses `H(t X)atprediction_time`
callable Uses callable(model, X) User-defined

Example using fixed-time event probability:

selector = RobustSurvivalFeatureSelectorCV(
    model=rsf,
    max_features=20,
    risk_score="event_probability",
    prediction_time=365,
    preset="safe",
)

Raw RSF risk scores may have different scales across CV folds. This package does not assume that raw survival risk scores are calibrated or directly comparable across folds. They are used for within-fold rank-based evaluation such as C-index.

If your risk-score function returns lower values for higher risk, use:

selector = RobustSurvivalFeatureSelectorCV(
    model=model,
    max_features=20,
    risk_score_direction="lower",
)

Advanced usage

Advanced settings are grouped into dictionaries.

selector = RobustSurvivalFeatureSelectorCV(
    model=rsf,
    max_features=20,
    preset="custom",
    cv_config={
        "outer_splits": 5,
        "inner_splits": 4,
        "survival_stratify": "event",
    },
    selection_config={
        "selection_rule": "one_se",
        "min_selection_rate": 0.5,
        "use_shadow": True,
        "k_grid": [5, 10, 15, 20],
    },
    importance_config={
        "method": "permutation",
        "scoring": "auto",
        "n_repeats": 10,
        "n_jobs": -1,
    },
)

Importance backends

Method Classification Regression Survival
"auto" SHAP when available, fallback otherwise SHAP when available, fallback otherwise permutation C-index
"shap" SHAP-based ranking SHAP-based ranking not the default
"permutation" metric-aligned permutation metric-aligned permutation metric-aligned permutation

When importance_config={"method": "permutation", "scoring": "auto"}, permutation importance is aligned with the optimization metric: log loss for classification, RMSE for regression, and C-index for survival.

Results

After fitting:

selector.selected_features_
selector.result_.outer_results
selector.result_.inner_results
selector.result_.selection_frequency
selector.summary()

Save all result tables and metadata:

selector.result_.save("fs_results")

This writes:

outer_results.csv
inner_results.csv
inner_details.csv
selection_frequency.csv
final_features.csv
ranking_outer_*.csv
config.json
metadata.json

Requirements files

The requirements/ directory provides install shortcuts. The authoritative dependency definitions remain in pyproject.toml.

pip install -r requirements/base.txt
pip install -r requirements/survival.txt
pip install -r requirements/shap.txt
pip install -r requirements/imbalance.txt
pip install -r requirements/all.txt

Development

git clone https://github.com/rik-yosh/ranking-feature-selector.git
cd ranking-feature-selector
pip install -e ".[dev]"
pytest -q
python -m build
python -m twine check dist/*

GitHub Actions publishing

This repository includes GitHub Actions workflows for tests and PyPI publishing.

  • .github/workflows/test.yml runs tests and package checks on pushes and pull requests.
  • .github/workflows/publish.yml builds and publishes on tags matching v*.

For PyPI Trusted Publishing, configure the PyPI project with your GitHub owner, repository, workflow filename, and environment before pushing the release tag.

Important limitations

  • The package targets research workflows and should not be used as the sole basis for clinical decision-making.
  • Outer-CV performance reflects fold-specific selected feature sets.
  • selected_features_ is a stability-based aggregate across outer folds.
  • Column-expanding preprocessing should be performed before using the selector.
  • Survival raw risk scores are not assumed to be comparable across CV folds.

License

MIT License. See LICENSE.

Metadata

Release files for ranking-feature-selector 0.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ranking-feature-selector 0.4.3
File Size Uploaded Provenance
ranking_feature_selector-0.4.3.tar.gz 40.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ranking-feature-selector 0.4.3
File Interpreter ABI Platform
ranking_feature_selector-0.4.3-py3-none-any.whl Python 3 none any Details

Total release size: 76.6 kB

Release files / ranking_feature_selector-0.4.3.tar.gz

Download URL ranking_feature_selector-0.4.3.tar.gz
Size 40.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1ed56d2763bfbfb1d5937bf90a23ac5423bbd8cf0bab040c7857043c0cee9cdc
BLAKE2b-256 checksum
How to use checksums
9f8d5c1d47ca4d668ab914997bef68ec1ea6cb6cd31158ac87829734d241045e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 8, 2026.

Transparency log

Release files / ranking_feature_selector-0.4.3-py3-none-any.whl

Download URL ranking_feature_selector-0.4.3-py3-none-any.whl
Size 36.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea09cd28e1073ce65dd77a0d1111fd78a88d003ce8a6dd145fb7d2b17fe91307
BLAKE2b-256 checksum
How to use checksums
efe430dbc5e523c0866d6e2a2a68357428c3dfe69a0242b38c350eb3e66eb26c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 8, 2026.

Transparency log

Security for ranking-feature-selector 0.4.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ranking_feature_selector-0.4.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 8, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.3 This release

2 release files Full provenance

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