A pruning algorithm for the scikit-learn RandomForestClassifier which minimizes model complexity while considering a user-specified tolerance for accuracy loss.
Project description
Purity-Threshold-Pruning
About
Purity Threshold Pruning is a bagging‑based tree‑ensemble pruning algorithm for scikit‑learn’s RandomForestClassifier that minimizes model complexity under a user‑specified accuracy‑loss tolerance.
The main advantages are:
- Explicitly consider node purity (i.e., class distribution), preventing the pruning of low purity nodes that may cause catastrophic accuracy degradation.
- Iteratively search for the minimum purity threshold that satisfies the tolerance, resulting in the smallest possible model that satisfies the desired performance.
- Systematical pruning prevents the model from overgrowing or being over-pruned.
Installation
From PyPI (recommended)
pip install purity-threshold-pruning
From GitHub
git clone https://github.com/Datou0718/Purity-Threshold-Pruning
cd Purity-Threshold-Pruning
pip install .
Quick Start
from PurityThresholdPruning import PurityThresholdPruning
from sklearn.ensemble import RandomForestClassifier
# train a Random Forest
rf = RandomForestClassifier(...)
rf.fit(X_train, y_train)
# Pruned the model with 5% tolerable accuracy loss
tolerance = 0.05
rf = PurityThresholdPruning(rf, tolerance, X_train, y_train)
API
PurityThresholdPruning(forest, tolerance, X_train, y_train)
- forest: a fitted
RandomForestClassifierwithoob_score=True. - tolerance: Maximum tolerable accuracy drop in OOB estimation (e.g.,
0.05for 5%). - X, y: Training data (np.ndarray) used to compute OOB score.
Returns the
RandomForestClassifierpruned with the minimum purity threshold.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file purity_threshold_pruning-0.1.0.tar.gz.
File metadata
- Download URL: purity_threshold_pruning-0.1.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cc370e7a31b46de3ee5ce1f4ec4bda6b79f8ff4b60d06b895aa1781214c1531
|
|
| MD5 |
0fe45ee3ab11e3c25c49a957a60547aa
|
|
| BLAKE2b-256 |
5e5ff3e7df864874adeaba6e303ca98f5a639d109f2fef3264b3f3068b28b531
|
File details
Details for the file purity_threshold_pruning-0.1.0-py3-none-any.whl.
File metadata
- Download URL: purity_threshold_pruning-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
567f4def609526b743ab7f0d80df36980eb32ae51d186e3cf53a7c95c77c8ff0
|
|
| MD5 |
134b689580365369125a29bc86e0522e
|
|
| BLAKE2b-256 |
bfadc8b028c125d55b9f27d2f8869822806c4ced39f2994d7be9881905f0a00f
|