Skip to main content

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 RandomForestClassifier with oob_score=True.
  • tolerance: Maximum tolerable accuracy drop in OOB estimation (e.g., 0.05 for 5%).
  • X, y: Training data (np.ndarray) used to compute OOB score. Returns the RandomForestClassifier pruned with the minimum purity threshold.

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

purity_threshold_pruning-0.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

purity_threshold_pruning-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file purity_threshold_pruning-0.1.0.tar.gz.

File metadata

File hashes

Hashes for purity_threshold_pruning-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6cc370e7a31b46de3ee5ce1f4ec4bda6b79f8ff4b60d06b895aa1781214c1531
MD5 0fe45ee3ab11e3c25c49a957a60547aa
BLAKE2b-256 5e5ff3e7df864874adeaba6e303ca98f5a639d109f2fef3264b3f3068b28b531

See more details on using hashes here.

File details

Details for the file purity_threshold_pruning-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for purity_threshold_pruning-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 567f4def609526b743ab7f0d80df36980eb32ae51d186e3cf53a7c95c77c8ff0
MD5 134b689580365369125a29bc86e0522e
BLAKE2b-256 bfadc8b028c125d55b9f27d2f8869822806c4ced39f2994d7be9881905f0a00f

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