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 and LightGBM-style histograms for pre-processing continuous features. The rust core is based on a maintained fork of XRF, the engine behind FRU.
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=Truedoes not append only new trees: a laterfitrebuilds 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.
The coverage badge reports Python package coverage from the Linux x86_64 CI job; it does not include Rust line coverage.
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.0a8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bankai_random_forest-0.1.0a8.tar.gz | 365.1 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| bankai_random_forest-0.1.0a8-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details |
| bankai_random_forest-0.1.0a8-cp311-abi3-manylinux_2_28_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| bankai_random_forest-0.1.0a8-cp311-abi3-manylinux_2_28_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| bankai_random_forest-0.1.0a8-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details |
| bankai_random_forest-0.1.0a8-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.0a8.tar.gz
| Download URL | bankai_random_forest-0.1.0a8.tar.gz |
|---|---|
| Size | 365.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24ea0a296caae715c7f5d9c190c8f3f85436c5e142c5e2e117e27ed0ecc7dd38
|
|
BLAKE2b-256 checksum How to use checksums |
133c4f7a7908947251d64efa011c44d0da7825b96500fa0e69eb045b32ea2143
|
| 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.0a8-cp311-abi3-win_amd64.whl
| Download URL | bankai_random_forest-0.1.0a8-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 285.5 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
552ca45a4e48e4394fe576a7bbd88d12ab4971ed27e21940c8748602530450e2
|
|
BLAKE2b-256 checksum How to use checksums |
63c0bfe86320a2f7385bdb5f27f44eb8fdaa2cea8bf48d1281ae8c5549e8f0c0
|
| 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.0a8-cp311-abi3-manylinux_2_28_x86_64.whl
| Download URL | bankai_random_forest-0.1.0a8-cp311-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 379.5 kB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
035b7c4c8e50e7fc4dd17854fa77390c7631b7885e89750208739d7995a3c766
|
|
BLAKE2b-256 checksum How to use checksums |
523ead4c39961d4fe6be125ab44eeefb6fa1ddf07fe6da1fb659117cc781fc6b
|
| 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.0a8-cp311-abi3-manylinux_2_28_aarch64.whl
| Download URL | bankai_random_forest-0.1.0a8-cp311-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 354.0 kB |
| Tags | CPython 3.11 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
1394a1a1d9fa1ef4c92a6340a0f0acaf8451a58560b8914503f0ab11662e79ff
|
|
BLAKE2b-256 checksum How to use checksums |
c5c80897ca391a2ae8a51a655ba0f3cec38ee23d01746f0a08a335983749f87f
|
| 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.0a8-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | bankai_random_forest-0.1.0a8-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 333.1 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b439b8b4e89f2105627ab0c4440496f567ade783d1724907753b7eba6c10ddb9
|
|
BLAKE2b-256 checksum How to use checksums |
030b930beca128f1c63ffe26b40ea15e2dd4dd697331f6d1f8adb6aafbe0e892
|
| 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.0a8-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | bankai_random_forest-0.1.0a8-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 361.3 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
58a70d8fe2a06a06e0b3d950c0ff19eedab50ba3b55d9d8cf62518def3e2695c
|
|
BLAKE2b-256 checksum How to use checksums |
1289969434a0aeaf4845e24653d102308b97b64d1ed2ba8f8bbdc06528ad45a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|