Python package implementing classification trees.
Project description
classtrees
classtrees is a lightweight Python package that implements fast classification trees and random forest. It combines a NumPy-friendly Python API with a compiled C backend to deliver efficient training and prediction for binary and multiclass classification.
Key Features
- Decision tree classifier with configurable tree height, split criteria, and feature subsampling
- Random forest ensemble with bootstrap aggregation and support for parallel training
- Predict class labels and class probabilities
- Built as a C extension for performance
- Designed for NumPy arrays and scientific workflows
Installation
Requirements
- Python 3.10 or newer
- NumPy
- C compiler with OpenMP support (required to build the C extension)
Install from PyPI
python -m pip install classtrees
Install from source
python -m pip install .
Quick Start
import numpy as np
from classtrees import ClassTree, RandomForest
# training data
X = np.random.randn(100, 5)
y = (X[:, 0] > 0).astype(np.int64)
# single decision tree
tree = ClassTree(max_height=5, random_state=42)
tree.fit(X, y)
y_pred = tree.predict(X)
proba = tree.predict_proba(X)
# random forest
forest = RandomForest(n_estimators=50, max_height=8, random_state=42, n_jobs=1)
forest.fit(X, y)
forest_pred = forest.predict(X)
forest_proba = forest.predict_proba(X)
API
ClassTree
A single decision tree classifier.
Constructor arguments:
impurity:'gini'or'entropy'(default:'gini')max_height: maximum tree height, orNoneto grow until no valid split remainsmin_samples_split: minimum samples required to split a node (default:2)min_samples_leaf: minimum samples required in each leaf node (default:1)max_features: number of features considered for splits, orNoneto use all featuresrandom_state: random seed for reproducible training
Methods:
fit(X, y): train the classifier on feature matrixXand labelsypredict(X): return predicted class labels for input samplespredict_proba(X): return predicted class probabilities
RandomForest
An ensemble of decision trees with bootstrap sampling.
Constructor arguments:
n_estimators: number of trees in the forest (default:100)impurity,max_height,min_samples_split,min_samples_leaf,max_features,random_state: same asClassTreen_jobs: number of worker threads for training and prediction (default:1). Use-1to enable all available cores.
Methods:
fit(X, y): train the forest ensemblepredict(X): return ensemble class predictionspredict_proba(X): return averaged class probabilities from all trees
Documentation
Full documentation is available in the project docs/ folder and online at:
License
This project is licensed under the BSD-3-Clause license. See LICENSE for details.
Project Links
- Homepage: https://github.com/kubek22/classtrees
- Repository: https://github.com/kubek22/classtrees
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
File details
Details for the file classtrees-1.1.2.tar.gz.
File metadata
- Download URL: classtrees-1.1.2.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea38475f492d641aaefe4ac6491629c58662e38ac73dcb7911d27e7c8fb1a543
|
|
| MD5 |
d7355c9ba022e52d69770bfb86652dca
|
|
| BLAKE2b-256 |
a768065a93493f974afcacb5ae68436ea73d4a6228fbbafab7a9215c4608a63c
|
Provenance
The following attestation bundles were made for classtrees-1.1.2.tar.gz:
Publisher:
wheels.yml on kubek22/classtrees
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
classtrees-1.1.2.tar.gz -
Subject digest:
ea38475f492d641aaefe4ac6491629c58662e38ac73dcb7911d27e7c8fb1a543 - Sigstore transparency entry: 1719720529
- Sigstore integration time:
-
Permalink:
kubek22/classtrees@cd3b81ca7a91bc93849ba562d93b699a7224fcd4 -
Branch / Tag:
refs/tags/v1.1.2 - Owner: https://github.com/kubek22
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@cd3b81ca7a91bc93849ba562d93b699a7224fcd4 -
Trigger Event:
push
-
Statement type: