shap-hypetune

raw JSON →
0.2.7 verified Fri May 01 auth: no python

A Python package for simultaneous hyperparameters tuning and feature selection for gradient boosting models (LightGBM, XGBoost, CatBoost, Random Forest). Current version: 0.2.7. Release cadence: occasional, last release Jun 2023.

pip install shap-hypetune
error ModuleNotFoundError: No module named 'shap_hypetune'
cause Library not installed or wrong Python environment.
fix
pip install shap-hypetune
error AttributeError: 'BoostingRFA' object has no attribute 'get_support'
cause Using version older than 0.2.6 where get_support() was added.
fix
Upgrade to shap-hypetune>=0.2.6: pip install --upgrade shap-hypetune
error ValueError: The estimator should be a string among 'lgbm', 'xgb', 'catboost', 'rf'
cause Passed an estimator string that is not recognized or a custom object incorrectly formatted.
fix
Use one of the supported strings: 'lgbm', 'xgb', 'catboost', 'rf' (for Random Forest).
error ImportError: cannot import name 'RFA' from 'shap_hypetune'
cause Trying to import the old alias 'RFA' which was renamed to 'BoostingRFA'.
fix
Use: from shap_hypetune import BoostingRFA
breaking In v0.2.7, numpy types np.bool, np.int, np.float were replaced by native Python types. If you rely on exact numpy dtypes in model outputs, upgrade numpy to >=1.20 and check your custom callbacks.
fix Upgrade to v0.2.7 or cast numpy types explicitly.
gotcha The 'n_iter' parameter controls both tuning and feature selection iterations; setting it too low may result in poor convergence. In BoostingRFA and BoostingRFE, n_iter is the total number of trials (if hyperopt=True) or grid points (if grid=True).
fix Use at least 10-20 iterations for tuning; increase if using hyperopt=True.
gotcha Feature selection methods (RFA, RFE) require a fitted model with feature importance; if you pass a custom estimator that does not provide 'feature_importances_', it will raise an error.
fix Use only LightGBM, XGBoost, CatBoost, or Random Forest as the base estimator, or ensure custom estimator has the attribute.
deprecated Usage of 'estimator' parameter as a string (e.g., 'lgbm') is stable, but passing a scikit-learn estimator object is experimental and may break in future versions.
fix Stick to string names for now; if you need a custom estimator, test thoroughly.

Basic usage: perform recursive feature addition with hyperparameter tuning using LightGBM. Note: estimator can be 'lgbm', 'xgb', 'catboost', or 'rf' (Random Forest, added in v0.2.4).

import pandas as pd
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from shap_hypetune import BoostingRFA

X, y = make_classification(n_samples=100, n_features=20, random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)

model = BoostingRFA(estimator='lgbm', n_iter=5, early_stopping_rounds=10, random_state=0)
model.fit(X_train, y_train)
print('Train accuracy:', model.score(X_train, y_train))
print('Selected features:', model.get_support())