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.0a1

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.0a1
File Size Uploaded
bankai_random_forest-0.1.0a1.tar.gz 203.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for bankai-random-forest 0.1.0a1
File
bankai_random_forest-0.1.0a1-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
bankai_random_forest-0.1.0a1-cp311-abi3-manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.28+ x86-64 Details
bankai_random_forest-0.1.0a1-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details
bankai_random_forest-0.1.0a1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
bankai_random_forest-0.1.0a1-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.0a1.tar.gz

Download URL bankai_random_forest-0.1.0a1.tar.gz
Size 203.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fba00dc8fc26bd02b2f6b4c1aa5c76293989bb946927737c80801e39862487cc
BLAKE2b-256 checksum
How to use checksums
cda4507143b994e74bcb70f7d3f6b0b6816b37837ab34332e1f89faf345dab54
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.0a1-cp311-abi3-win_amd64.whl

Download URL bankai_random_forest-0.1.0a1-cp311-abi3-win_amd64.whl
Size 231.3 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
bb45f2f9c1c01d8b8cdb404e765261f585455b2af14b894d61878ccd053fad2b
BLAKE2b-256 checksum
How to use checksums
3719d4b295ae13f0fac7778787eff4369ff1be1395224754d73097b56dcb427a
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.0a1-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL bankai_random_forest-0.1.0a1-cp311-abi3-manylinux_2_28_x86_64.whl
Size 325.0 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
2fa8a0198bc594ebe4ced63e9f3bb9fb1a4f8fe6113bc3b6843236b69981101e
BLAKE2b-256 checksum
How to use checksums
7e4643ee127d1bd2ff810de36589f98bfc078584584f59fcac75a682d9b1f541
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.0a1-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL bankai_random_forest-0.1.0a1-cp311-abi3-manylinux_2_28_aarch64.whl
Size 305.7 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
fae27b1ffba93f4b654f96766dc8e2f3ed391a689617d905b27b37ed77378936
BLAKE2b-256 checksum
How to use checksums
0f5eff9dbc507c3c20c7efc482cf89b6a667fb70d6cb7f6ea8281bd0ecd9f009
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.0a1-cp311-abi3-macosx_11_0_arm64.whl

Download URL bankai_random_forest-0.1.0a1-cp311-abi3-macosx_11_0_arm64.whl
Size 287.1 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
81b7a07731b2c8530d8f9db82e450657cf0a46f47f4d99a924cf242d29ca3630
BLAKE2b-256 checksum
How to use checksums
f50615ccbb09039d4c9bb3707dc1ad59e9cb2b43fbc287eb86e7c9304e88cf0e
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.0a1-cp311-abi3-macosx_10_12_x86_64.whl

Download URL bankai_random_forest-0.1.0a1-cp311-abi3-macosx_10_12_x86_64.whl
Size 306.3 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
162eee973d41c2114b3dc21cacd391fafbe3d5fcfe3454babdf95159fbb5e8a5
BLAKE2b-256 checksum
How to use checksums
d4d89431ecead9426910fecf141f85cae288b515c429853a3982a15a841dbae7
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