Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Bankai Random Forest

Bankai is a scikit-learn-compatible random forest classifier with a native Rust backend. The project is in alpha; APIs and serialized models may change. The roadmap and compatibility details are in docs/ROADMAP.md and docs/SKLEARN_COMPATIBILITY.md.

Install from source

Python 3.11 or newer and a Rust toolchain are required to build the extension. From the repository root:

uv sync
uv run maturin develop --release

The --release flag builds the optimized native extension. Then install the package in your Python environment using the workflow above and import it as shown below.

Quick start

BankaiRandomForestClassifier follows the familiar scikit-learn estimator API:

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

from bankai_random_forest import BankaiRandomForestClassifier

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42, stratify=y
)

model = BankaiRandomForestClassifier(
    n_estimators=100,
    random_state=42,
    max_bins=64,  # omit this or use None for exact split search
)
model.fit(X_train, y_train)

predictions = model.predict(X_test)
probabilities = model.predict_proba(X_test)
print(f"Accuracy: {accuracy_score(y_test, predictions):.3f}")
print("Feature importances:", model.feature_importances_)

The classifier works with scikit-learn utilities such as Pipeline, cross_val_score, and GridSearchCV. Features should be numeric; encode categorical columns with a transformer such as OneHotEncoder in a pipeline.

Common options

  • n_estimators, max_depth, min_samples_split, min_samples_leaf, max_features, bootstrap, max_samples, class_weight, and random_state control forest fitting.
  • max_bins=None uses exact split search. An integer from 2 to 255 enables histogram split search; for example, max_bins=64.
  • ccp_alpha prunes trees. monotonic_cst accepts one -1, 0, or 1 per feature and is supported for binary classification.
  • oob_score=True enables out-of-bag estimates when bootstrap=True.
  • importance_type selects "gain" (default), "split", or "permutation". Permutation importance requires bootstrap=True.
  • Dense arrays and SciPy CSR/CSC matrices are supported, including NaN feature values. Missing values are routed by the fitted trees; categorical values are not automatically encoded.

Multioutput and multilabel targets are supported. Bankai trains one native forest per output, whereas scikit-learn shares tree structures across outputs; therefore trees and probabilities need not match exactly. For multioutput models, estimators_, apply, decision_path, and TreeSHAP inspect the first output forest. Monotonic constraints currently apply only to binary single- output classification.

TreeSHAP

Install SHAP in the same environment (python -m pip install shap), then pass the fitted classifier directly to TreeExplainer:

import shap

explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X_test)

This integration supports single-output classifiers. See docs/SKLEARN_COMPATIBILITY.md for the multioutput inspection limitation and compatibility status.

Save and restore a fitted model

import joblib

joblib.dump(model, "classifier.joblib")
restored_model = joblib.load("classifier.joblib")
predictions = restored_model.predict(X_test)

Bankai's joblib state includes the training arrays and rebuilds the native forest while loading, so loading has reconstruction cost and artifacts may be large. Keep Bankai, Python, and dependency versions consistent when restoring models. Only load joblib files from trusted sources. Details are in docs/JOBLIB_COMPATIBILITY.md.

Development and tests

uv run pytest -q
uv run cargo test --workspace

Install benchmark-only dependencies with uv sync --group benchmark.

Optimized cp311-abi3 wheels were built and tested locally on Python 3.11, 3.12, and 3.13. The full Python suite passed (147 tests) against each installed wheel. Release signing remains future work.

The project is licensed under GPL-3.0-or-later; see COPYING.

Metadata

Release files for bankai-random-forest 0.1.0a3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bankai-random-forest 0.1.0a3
File Size Uploaded
bankai_random_forest-0.1.0a3.tar.gz 237.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for bankai-random-forest 0.1.0a3
File
bankai_random_forest-0.1.0a3-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
bankai_random_forest-0.1.0a3-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details
bankai_random_forest-0.1.0a3-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details
bankai_random_forest-0.1.0a3-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
bankai_random_forest-0.1.0a3-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details

Total release size: 1.7 MB

Release files / bankai_random_forest-0.1.0a3.tar.gz

Download URL bankai_random_forest-0.1.0a3.tar.gz
Size 237.7 kB
Tags Source
SHA-256 checksum
How to use checksums
43855dac976af9a77acfc9c06458a02a9c346fa4f3d9e34e086e9e07c5068ba8
BLAKE2b-256 checksum
How to use checksums
a46c87fb138fb323c3c949354a97692b06d15af1bfa815b1164d05948b8f551f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / bankai_random_forest-0.1.0a3-cp311-abi3-win_amd64.whl

Download URL bankai_random_forest-0.1.0a3-cp311-abi3-win_amd64.whl
Size 242.5 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
c70d5e4c85dd88d81c9cbe6bda67f77df5701f64bff42f5bf9f9dd2e211cd951
BLAKE2b-256 checksum
How to use checksums
607bea99c2ee570633a3e303879058e20ee13a620c8b7eb7efbbdcf1fb3ac1f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / bankai_random_forest-0.1.0a3-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL bankai_random_forest-0.1.0a3-cp311-abi3-manylinux_2_28_x86_64.whl
Size 336.5 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
8b202aa2f9f1a78a3d019727b107b06dc7fc95ee21108fd70deb7a56e3a96354
BLAKE2b-256 checksum
How to use checksums
53eeee3185b340f5a657b491610c78777567c4807c827029417d26e427d0d184
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / bankai_random_forest-0.1.0a3-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL bankai_random_forest-0.1.0a3-cp311-abi3-manylinux_2_28_aarch64.whl
Size 315.3 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
17f4d8dea41daff37c5fa49a5e1693c4afdf4bc5efcc89695b3e0e74e7d8b1d8
BLAKE2b-256 checksum
How to use checksums
3f44050f3727035a363016500a320dc44900a98dfef31ae36fdf9c2e245e565d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / bankai_random_forest-0.1.0a3-cp311-abi3-macosx_11_0_arm64.whl

Download URL bankai_random_forest-0.1.0a3-cp311-abi3-macosx_11_0_arm64.whl
Size 296.5 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8c4cd443b2b9c25712c356169ebfcfe2d1c4272158fabfb171278b095c7505e2
BLAKE2b-256 checksum
How to use checksums
f27aae832307a63e2fa4575a80a4e0f977448db6db3561f7d605da4c1528b162
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / bankai_random_forest-0.1.0a3-cp311-abi3-macosx_10_12_x86_64.whl

Download URL bankai_random_forest-0.1.0a3-cp311-abi3-macosx_10_12_x86_64.whl
Size 316.9 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f17bd21e658f451b11059a927aa2e7a4537e7c0cf19bedf5ce952473616d9fc2
BLAKE2b-256 checksum
How to use checksums
2bae7f6b7c78a58f6a4a6330f397b515a95049bd0659abf1c91da7598c130516
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page