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.
  • With histogram mode enabled, binning_strategy chooses how cuts are built: exact_sort (default), sampled_sort, exact_select, or sampled_select. Sampled modes use up to bin_sample_size rows per feature (default 200,000). Selection modes avoid a full sort by selecting empirical quantile ranks; repeated values can therefore produce different cuts than exact_sort.
  • 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.0a4

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

Built distributions (wheels)

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

Total release size: 2.0 MB

Release files / bankai_random_forest-0.1.0a4.tar.gz

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

Download URL bankai_random_forest-0.1.0a4-cp311-abi3-win_amd64.whl
Size 282.3 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
269408650c550c7a84248591c651485549e5e1f2ac164316f03c8b1d43500feb
BLAKE2b-256 checksum
How to use checksums
32ea6c75318c7c972766328ba072cf085b13f57ddcf87a1e244d9f17887741f5
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.0a4-cp311-abi3-manylinux_2_28_x86_64.whl

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

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

Download URL bankai_random_forest-0.1.0a4-cp311-abi3-macosx_11_0_arm64.whl
Size 330.6 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ecd0a14ed5f5336ef7b4841215068c55dc5b9d1b3fab2cf451a00bffa7ef20ed
BLAKE2b-256 checksum
How to use checksums
99ff1766e71ace53df88cbe8b2f88ff6a1ed5e6da4213c334f8846d98e8f5f00
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.0a4-cp311-abi3-macosx_10_12_x86_64.whl

Download URL bankai_random_forest-0.1.0a4-cp311-abi3-macosx_10_12_x86_64.whl
Size 358.1 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
2c160c65ec1fad66b5873c0c09a018d59cd6820cd2c75f74b1ac153da654bcda
BLAKE2b-256 checksum
How to use checksums
412efbc6926d00314dbc09b21ddd5f21e4ff6fa6be9aa152365e9a8dfb37acf4
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