Skip to main content

A Python package for the SHAPBoost feature selection algorithm

Project description

SHAPBoost

Python implementation of SHAPBoost. See the paper for details. R implementation is available here.

Usage

pip install shapboost

Example regression

from shapboost import SHAPBoostRegressor
from xgboost import XGBRegressor

X = ...  # feature matrix
y = ...  # target vector
clf = SHAPBoostRegressor(
    XGBRegressor(),
    metric="mae",
    verbose=2,
    siso_ranking_size=20,
    max_number_of_features=2,
    num_resets=1,
    use_shap=True,
    collinearity_check=True,
)
clf.fit(X, y)
print(clf.selected_subset_)

For a more detailed example, see the regression example.

Example survival

from shapboost import SHAPBoostSurvivalRegressor
from shapboost.helpers import XGBSurvivalRegressor, RandomSurvivalForestWrapper
import pandas as pd

df = ...  # df with event, upper_bound, lower_bound and features
X = df.drop(columns=["event", "upper_bound", "lower_bound"])
y = df[["lower_bound", "upper_bound"]]
clf = SHAPBoostSurvivalRegressor(estimator=estimator)

feature_selector = SHAPBoostSurvivalRegressor(
    [XGBSurvivalRegressor(**best_params), RandomSurvivalForestWrapper()],
    metric="c_index",
    verbose=0,
    siso_ranking_size=50,
    max_number_of_features=100,
    num_resets=1,
)
feature_selector.fit(X, y)
print(clf.selected_subset_)

For a more detailed example, see the survival example.

Feature selection methods

SHAPBoost is available for regression, and survival problems.

  • Regression supports the mae, mse, and r2 objectives through the SHAPBoostRegressor-class and can be optimized through adaptive boosting.
  • Survival supports the c_index objective through the SHAPBoostRegressor-class and can be optimized through adaptive boosting.

Important notes

  • The estimator hyperparameter sets the estimators used for the SISO- and MISO steps, and for the updating of the sample weights (or the boosting), the first estimator is used. Thus, this first estimator needs to be a tree model that supports the sample_weight parameter.

Illustration of SHAPBoost

Figure 1

Project details


Download files

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

Source Distribution

shapboost-1.0.1.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

shapboost-1.0.1-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file shapboost-1.0.1.tar.gz.

File metadata

  • Download URL: shapboost-1.0.1.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for shapboost-1.0.1.tar.gz
Algorithm Hash digest
SHA256 75fa8d6d0d9b4d8dfc2eab7c077fa8cf51b9fb7c7d257893e63596eab38a2240
MD5 80e408f3a79bdad3794f1fcbf6269bfe
BLAKE2b-256 a02232c77dc5dc457cead852249ff20ff9bd619ff654f8044ddd2fbf0d94d0a2

See more details on using hashes here.

File details

Details for the file shapboost-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: shapboost-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for shapboost-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 561440d992c231d7eb1021eb34c69e7bbda5ae4c3d45a097a3ab0dfd1783c014
MD5 87ba2c258fae13f32b3e012f3cd5d38d
BLAKE2b-256 584e278d57f267a6f14273c1ef38465ce3bc87f12518fc0dd8d20ad5a5df1245

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page