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 high-performance random forest for Python, powered by a native Rust core based on a maintained fork of XRF, the engine behind FRU. It combines parallel tree building and efficient permutation importance with optional LightGBM-style histograms for continuous features.

Preliminary results from an earlier run of the Colab benchmark reported Bankai's fit-plus-OOB-permutation workload 21× faster than scikit-learn fit plus validation permutation importance, and Bankai histogram fit 1.8× faster than LightGBM RF. These figures have not been remeasured with the notebook's current 1,000-row setup and are workload- and hardware-specific; see the notebook for current settings and comparison caveats.

Bankai follows the familiar scikit-learn estimator API, and full compatibility is a project goal. The project is in alpha, so APIs and serialized models may change.

Install

Python 3.11 or newer is required. Install the package from PyPI:

python -m pip install bankai-random-forest

Quick start

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

from bankai_random_forest import BankaiRandomForestClassifier

X, y = load_breast_cancer(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=200,
    max_bins=63,
    binning_strategy="sampled_select",
    importance_type="permutation",
    n_jobs=-1,
    random_state=42,
)
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("Probabilities:", probabilities[:3])
print("Feature importances:", model.feature_importances_)

max_bins enables histogram-based split search in this example. Set max_bins=None to use exact split search. Histogram cuts can change the fitted trees and the accuracy/speed trade-off; evaluate both on your data when that matters.

Training options

Bankai follows the familiar RandomForestClassifier estimator pattern and supports common options such as n_estimators, criterion, max_depth, min_samples_split, min_samples_leaf, max_features, max_leaf_nodes, bootstrap, max_samples, class_weight, random_state, n_jobs, oob_score, and ccp_alpha.

Option Behavior
n_jobs None uses one worker. Negative values follow joblib-style CPU-count rules; n_jobs=-1 uses all visible logical CPUs.
max_bins None (default) uses exact split search. An integer from 2 to 255 enables histogram training.
binning_strategy With histograms, choose exact_sort (default), sampled_sort, exact_select, or sampled_select.
bin_sample_size Maximum number of rows used per feature by sampled strategies; defaults to 200,000.
importance_type gain (default), split, or permutation. Permutation importance uses out-of-bag accuracy decrease and requires bootstrap=True; it can add fit time.
monotonic_cst One -1, 0, or 1 constraint per feature; currently limited to binary, single-output classification without NaN values.

Sampled binning strategies use a deterministic subset of rows to construct feature cuts. Selection strategies avoid fully sorting each feature, while repeated feature values can produce cuts that differ from the sort strategies. For reproducible model comparisons, keep the strategy, sample size, seed, and thread count fixed.

API and supported inputs

  • Dense NumPy arrays and SciPy CSR/CSC matrices are supported. Numeric features are expected; encode categorical columns in a scikit-learn transformer such as OneHotEncoder.
  • NaN feature values are supported in dense and sparse inputs and are routed by the fitted trees. Infinite values are rejected.
  • Binary, multiclass, multioutput, and multilabel classification targets are supported. Bankai trains a separate native forest for each output, so its multioutput trees and probabilities need not match scikit-learn's shared-tree implementation.
  • feature_importances_ defaults to gain-based importance; its values are not guaranteed to match scikit-learn's impurity importance. Bankai also provides split-count and out-of-bag permutation importance.
  • warm_start=True does not append only new trees: a later fit rebuilds the forest. For multioutput models, estimators_, apply, decision_path, and TreeSHAP inspection expose the first output forest.

Tested with scikit-learn 1.9.1 (>=1.9.1,<1.10).

Feature explanations

SHAP is optional and is not a runtime dependency. For TreeSHAP, pass a fitted single-output classifier directly to TreeExplainer:

import shap

explainer = shap.TreeExplainer(model)
explanation = explainer(X_test[:10])

See the SHAP compatibility notes for output shapes, multioutput limitations, and model-agnostic alternatives.

Performance

Fit time depends on the data, tree settings, hardware, and importance calculation. The benchmark report includes stage breakdowns, later Bankai measurements, and comparison caveats; results are specific to the recorded workload and are not a performance guarantee.

Run the binary classification fit benchmark in Google Colab or view the notebook in this repository. It compares scikit-learn RF, LightGBM RF, and Bankai on one shared dataset with n_jobs=-1; the first cell installs the packages. The scikit-learn comparison times fit plus validation permutation importance against Bankai fit with OOB permutation importance. The LightGBM comparison remains fit-only with gain on both models.

Save and restore models

Fitted models can be saved with joblib:

import joblib

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

Bankai's serialized state includes training arrays and rebuilds the native forest when loaded. Loading therefore has reconstruction cost and model files can be large. Keep Bankai and Python versions consistent when restoring a model, and only load joblib files from trusted sources. See the serialization notes.

Development

Building from source requires Python 3.11 or newer, Rust, and uv:

uv sync --locked --no-install-project
uv run maturin develop --release --locked
uv run pytest -q
uv run cargo test --workspace --locked

Install optional benchmark dependencies with uv sync --locked --group benchmark. The roadmap tracks project status and planned work.

License

Bankai is licensed under GPL-3.0-or-later. The maintained XRF fork is also GPL-3.0-or-later; see NOTICE for upstream attribution.

Metadata

Release files for bankai-random-forest 0.1.0a5

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

Built distributions (wheels)

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

Download URL bankai_random_forest-0.1.0a5.tar.gz
Size 261.5 kB
Tags Source
SHA-256 checksum
How to use checksums
811efd3eeafeec2c389ac10788b2b52dd01b30327798a13ca6af18111b76b15d
BLAKE2b-256 checksum
How to use checksums
c6209c4bf432b094f998ab8238fc51e410f52d91fb06815a631174eba7874cbe
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.0a5-cp311-abi3-win_amd64.whl

Download URL bankai_random_forest-0.1.0a5-cp311-abi3-win_amd64.whl
Size 283.3 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
1ca64e2bf3399ffe749b8601094da1091026e593e5d7bb8a61860bbc02777d02
BLAKE2b-256 checksum
How to use checksums
1111a48a1c18c91002e2934521506ffffdd90b2b19cc7159ea66ce10b44978cb
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.0a5-cp311-abi3-manylinux_2_28_x86_64.whl

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

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

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

Download URL bankai_random_forest-0.1.0a5-cp311-abi3-macosx_10_12_x86_64.whl
Size 359.0 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
5ea7eceab3eaeecb059416a4f88bdd9443ea93b73f6f5921867160c33f25ac0d
BLAKE2b-256 checksum
How to use checksums
fa0f9d76aefc3dd1a7107320934d3e23268ea876d5ff9437aa03d6337828d537
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