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

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

Built distributions (wheels)

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

Total release size: 2.1 MB

Release files / bankai_random_forest-0.1.0a7.tar.gz

Download URL bankai_random_forest-0.1.0a7.tar.gz
Size 337.7 kB
Tags Source
SHA-256 checksum
How to use checksums
51c1d62325e21e1ef2e6bcee5198b7c6e943595b9a2fdec51832c9275ec8c3aa
BLAKE2b-256 checksum
How to use checksums
3173df85cb1952b07f979b773f4a29868e4545db1c5b4274acfc9fb1ab46fffb
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.0a7-cp311-abi3-win_amd64.whl

Download URL bankai_random_forest-0.1.0a7-cp311-abi3-win_amd64.whl
Size 285.4 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
f89980b5a86c518b2f2f930c6f031c908ee74c63c651132b4e9a080d3f3378c4
BLAKE2b-256 checksum
How to use checksums
4340b0f6080bb138f45cce335104fe28261cbc4a48fb8fd9240bc96f1d331abd
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.0a7-cp311-abi3-manylinux_2_28_x86_64.whl

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

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

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

Download URL bankai_random_forest-0.1.0a7-cp311-abi3-macosx_10_12_x86_64.whl
Size 361.1 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c9d16a3603e598d6985c8922c95aeb765c932737bd173be2549251950d84ccb8
BLAKE2b-256 checksum
How to use checksums
879da46e4cacda1d8ae46ada5385c0626f16ea8be0197ac9e8d3c3044be967d3
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