A modernized fork of BorutaShap that works with current versions of NumPy, SciPy, and scikit-learn. This fork includes performance improvements and bug fixes for SHAP-based feature selection.
- NumPy 2.0+ support: Fixed deprecated
np.NaN→np.nan - SciPy 1.11+ support: Updated
binom_test→binomtestwith backward compatibility - Python 3.12 support: Fully tested with Python 3.9 through 3.12
- RandomForest + SHAP: Fixed 3D array handling and indexing issues
- RandomForest + Gini: Fixed premature feature_importances_ check
- Missing imports: Added required imports (inspect, defaultdict)
Based on extensive benchmarking:
- LightGBM: Best overall performer (0.6s avg SHAP time, F1=0.875)
- XGBoost: Good balance (1.6s avg SHAP time, F1=0.868)
- RandomForest: Best F1 on small datasets (F1=0.935 @ 1k samples)
- GradientBoosting: Highest accuracy but slow (13s avg SHAP time)
# Clone this fork
git clone https://github.com/BlackArbsCEO/Boruta-Shap.git
cd Boruta-Shap
# Install in development mode
pip install -e .
# Or install directly from GitHub
pip install git+https://github.com/BlackArbsCEO/Boruta-Shap.gitnumpy>=1.24.0
pandas>=1.5.0
scipy>=1.10.0
scikit-learn>=1.2.0
shap>=0.41.0
tqdm>=4.65.0
lightgbm>=3.3.0 # Optional but recommended
xgboost>=1.7.0 # Optionalfrom BorutaShap import BorutaShap
from lightgbm import LGBMClassifier
from sklearn.datasets import make_classification
import pandas as pd
# Generate sample data
X, y = make_classification(n_samples=1000, n_features=20, n_informative=10)
X = pd.DataFrame(X, columns=[f'feature_{i}' for i in range(20)])
# Initialize with LightGBM (recommended for speed)
model = LGBMClassifier(n_estimators=50, max_depth=5, verbose=-1)
# Run BorutaShap
fs = BorutaShap(
model=model,
importance_measure='shap', # or 'gini' for tree-based models
classification=True
)
fs.fit(X=X, y=y, n_trials=100, random_state=42)
# Get results
print(f"Accepted features: {fs.accepted}")
print(f"Rejected features: {fs.rejected}")
print(f"Tentative features: {fs.tentative}")| Use Case | Recommended Model | F1 Score | SHAP Speed |
|---|---|---|---|
| Small data (<5k samples) | RandomForest | 0.935 | 0.15s |
| Medium data (5-50k) | LightGBM | 0.90 | 0.5-2s |
| Large data (>50k) | LightGBM | 0.89 | 2-5s |
| Best accuracy | GradientBoosting | 0.91 | 10-50s |
| Production/speed critical | LightGBM | 0.88 | <2s |
- Samples: More samples → better F1 (all models improve 5-9%)
- Features: More features → worse F1 (especially RandomForest: -15% from 10→200 features)
- Sweet spot: 5-10k samples with ≤50 features
- SHAP: More accurate but ~11x slower than Gini
- Gini: Fast but only for tree-based models (not XGBoost)
- Recommendation: Use SHAP for final models, Gini for exploration
✅ Fully Supported:
- LightGBM (fastest SHAP)
- XGBoost (SHAP only)
- RandomForest (both SHAP and Gini)
- ExtraTrees (both SHAP and Gini)
- GradientBoosting (both SHAP and Gini)
❌ Not Supported:
- BaggingClassifier (SHAP TreeExplainer incompatible)
- SVM, Neural Networks (no tree structure)
# Run basic test
python examples/test_basic.py
# Run performance comparison
python examples/compare_models.py
# Test with your data
python examples/test_custom.py --data your_data.csv- Fixed NumPy 2.0 compatibility (src/BorutaShap.py:L384-394)
- Fixed SciPy binomial test import (src/BorutaShap.py:L8-13)
- Fixed RandomForest SHAP 3D array handling (src/BorutaShap.py:L250-260)
- Fixed RandomForest Gini importance check (src/BorutaShap.py:L150-155)
- Added Python 3.12 support (setup.py)
- Added comprehensive benchmarks (examples/benchmark.py)
If you use this fork, please cite both the original and this fork:
# Original BorutaShap
@software{boruta_shap,
author = {Eoghan Keany},
title = {BorutaShap: A wrapper feature selection method using Boruta and SHAP},
url = {https://github.com/Ekeany/Boruta-Shap},
year = {2020}
}
# This fork
@software{boruta_shap_modern,
author = {BlackArbsCEO},
title = {BorutaShap Modern Fork: Compatible with NumPy 2.0+},
url = {https://github.com/BlackArbsCEO/Boruta-Shap},
year = {2025}
}Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Run tests with Python 3.9+
- Submit a pull request
MIT License (same as original)
- Original author: Eoghan Keany
- SHAP library: lundberg/shap
- Boruta algorithm: Boruta R package