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.0.tar.gz (23.6 kB view details)

Uploaded Source

File details

Details for the file classtrees-1.1.0.tar.gz.

File metadata

  • Download URL: classtrees-1.1.0.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for classtrees-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e5b1348b44d5348187f245764049b20297d61def720326d2fb081592a55adcdb
MD5 432cc930864dd3f3362fdcc9799a8c67
BLAKE2b-256 cfb6c2c0c9b9f09d8a0be8bb46cfe6775f71c68731846ebeef8463c698d25891

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