A rich documentation is available at Read the Docs
Shape Penalized Decision Forests
Shape Penalized Decision Forests, for training ensemble classifiers tailored for imbalanced datasets. This package provides two primary implementations:
-
SPBoDF (Shape Penalized Boosting Decision Forest): A boosting ensemble method that builds multiple trees sequentially, adjusting the weights of samples to focus on harder-to-classify instances.
-
SPBaDF (Shape Penalized Bagging Decision Forest): A bagging ensemble method that builds multiple trees independently on bootstrap samples of the dataset, improving robustness and reducing overfitting.
Both implementations use the concept of Surface-to-Volume Regularization (SVR) to penalize irregular decision boundaries, thus improving generalization and addressing challenges associated with imbalanced datasets.
Key Features
- Boosting and Bagging: Two ensemble approaches tailored for classification tasks.
- Shape Penalization: Incorporates a novel regularization technique to control decision boundary complexity.
- Imbalanced Data Handling: Designed with class imbalance in mind, using weighting and bootstrapping techniques.
- Scikit-learn Compatible: Implements
BaseEstimatorandClassifierMixin, making it seamlessly integrable with the Scikit-learn ecosystem. - Customizability: Hyperparameters such as the number of trees, shape penalty, and maximal leaves are configurable for fine-tuning.
Installation
-
Downloading Locally and Installing
git clone https://www.github.com/yuvrajiro/imbalanced-spdf.git cd imbalance-spdf
-
Install dependencies:
pip install -r requirements.txt
-
Install the package:
python install -e .
-
Using pip install from GitHub
pip install git+https://www.github.com/yuvrajiro/imbalanced-spdf.git
-
Using pip install from PyPi
pip install imbalanced-spdf
Usage
1. SPBoDF (Boosting)
Example
import numpy as np
from imbalanced_spdf.ensemble import SPBoDF
# Generate synthetic data
X_train = np.random.rand(100, 5)
y_train = np.random.randint(0, 2, 100)
# Initialize and fit SPBoDF
boosting_model = SPBoDF(n_trees=50, weight=2, pen=1.0, random_state=42)
boosting_model.fit(X_train, y_train)
# Predict
X_test = np.random.rand(20, 5)
y_pred = boosting_model.predict(X_test)
print("Predictions:", y_pred)
2. SPBaDF (Bagging)
Example
from imbalanced_spdf.ensemble import SPBaDF
# Generate synthetic data
X_train = np.random.rand(100, 5)
y_train = np.random.randint(0, 2, 100)
# Initialize and fit SPBaDF
bagging_model = SPBaDF(n_trees=50, weight=2, pen=1.0, random_state=42)
bagging_model.fit(X_train, y_train)
# Predict
X_test = np.random.rand(20, 5)
y_pred = bagging_model.predict(X_test)
print("Predictions:", y_pred)
API Reference
SPBoDF
A boosting ensemble classifier that uses SVR-regularized trees to handle imbalanced datasets.
Parameters:
n_trees(int): Number of trees in the ensemble (default: 40).weight(float): Weight for the minority class to address imbalance (default: 1).pen(float): Regularization penalty controlling decision boundary complexity (default: 0).maximal_leaves(int or float, optional): Maximum leaves per tree. Defaults to2 * sqrt(n_samples) * 0.3333.random_state(int): Random seed for reproducibility (default: 23).
Methods:
fit(X, y): Fits the ensemble on the training data.predict(X): Predicts the labels of the test data.
SPBaDF
A bagging ensemble classifier that uses SVR-regularized trees to improve robustness.
Parameters:
n_trees(int): Number of trees in the ensemble (default: 40).weight(float): Weight for the minority class to address imbalance (default: 1).pen(float): Regularization penalty controlling decision boundary complexity (default: 0).maximal_leaves(int or float, optional): Maximum leaves per tree. Defaults to2 * sqrt(n_samples) * 0.3333.random_state(int): Random seed for reproducibility (default: 23).
Methods:
fit(X, y): Fits the ensemble on the training data.predict(X): Predicts the labels of the test data.
How It Works
-
SPBoDF (Boosting):
- Trees are built sequentially, with sample weights updated after each iteration to focus on misclassified samples.
- Regularization (SVR) penalizes irregular decision boundaries to avoid overfitting.
-
SPBaDF (Bagging):
- Trees are built independently on bootstrap samples of the training data.
- Each tree focuses on non-constant feature subsets, improving robustness and generalization.
Dataset Details
License
This project is licensed under the MIT License. See the LICENSE file for details.
Citation
If you are using this package in your research, please consider citing the following paper:
Shape Penalized Decision Forests for Imbalanced Data Classification : Rahul Goswami, Aindrila Garai, Payel Sadhukhan, Palash Ghosh, Tanujit Chakraborty
References
- Zhu, Y., Li, C., & Dunson, D. B. (2023). "Classification Trees for Imbalanced Data: Surface-to-Volume Regularization." Journal of the American Statistical Association.
Metadata
Release files for imbalanced-spdf 0.0.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| imbalanced_spdf-0.0.18.tar.gz | 20.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| imbalanced_spdf-0.0.18-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.1 kB
Release files / imbalanced_spdf-0.0.18.tar.gz
| Download URL | imbalanced_spdf-0.0.18.tar.gz |
|---|---|
| Size | 20.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e90ca8c1bf7160b79ff0fd5ae227e9bb09c023f70b70674c6e9be01e636203b3
|
|
BLAKE2b-256 checksum How to use checksums |
01e6022380d1b0153b4a5e7d61f0ab26d100b799707db0e93e9320825c35702e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.13
|
Release files / imbalanced_spdf-0.0.18-py3-none-any.whl
| Download URL | imbalanced_spdf-0.0.18-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ed7170083d4d21c3a133df42b1970d4be847783cca1fcc257d128afa8374e52
|
|
BLAKE2b-256 checksum How to use checksums |
6bf9ea67e92983039eb7bdfc88460dd6a555227d656ccb57b045e103f3158264
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.13
|
Security for imbalanced-spdf 0.0.18
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.