Skip to main content

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, or None to grow until no valid split remains
  • min_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, or None to use all features
  • random_state: random seed for reproducible training

Methods:

  • fit(X, y): train the classifier on feature matrix X and labels y
  • predict(X): return predicted class labels for input samples
  • predict_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 as ClassTree
  • n_jobs: number of worker threads for training and prediction (default: 1). Use -1 to enable all available cores.

Methods:

  • fit(X, y): train the forest ensemble
  • predict(X): return ensemble class predictions
  • predict_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

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

classtrees-1.1.2.tar.gz (22.8 kB view details)

Uploaded Source

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

Hashes for classtrees-1.1.2.tar.gz
Algorithm Hash digest
SHA256 ea38475f492d641aaefe4ac6491629c58662e38ac73dcb7911d27e7c8fb1a543
MD5 d7355c9ba022e52d69770bfb86652dca
BLAKE2b-256 a768065a93493f974afcacb5ae68436ea73d4a6228fbbafab7a9215c4608a63c

See more details on using hashes here.

Provenance

The following attestation bundles were made for classtrees-1.1.2.tar.gz:

Publisher: wheels.yml on kubek22/classtrees

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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