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, andrandom_statecontrol forest fitting.max_bins=Noneuses exact split search. An integer from 2 to 255 enables histogram split search; for example,max_bins=64.ccp_alphaprunes trees.monotonic_cstaccepts one-1,0, or1per feature and is supported for binary classification.oob_score=Trueenables out-of-bag estimates whenbootstrap=True.importance_typeselects"gain"(default),"split", or"permutation". Permutation importance requiresbootstrap=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.0a2
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.0a2.tar.gz | 231.1 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| bankai_random_forest-0.1.0a2-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details |
| bankai_random_forest-0.1.0a2-cp311-abi3-manylinux_2_28_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| bankai_random_forest-0.1.0a2-cp311-abi3-manylinux_2_28_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| bankai_random_forest-0.1.0a2-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details |
| bankai_random_forest-0.1.0a2-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.0a2.tar.gz
| Download URL | bankai_random_forest-0.1.0a2.tar.gz |
|---|---|
| Size | 231.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42a025e94d16fd84ef1a9ea0788b75fb93a31be0327bb5b09f8e602cc8147082
|
|
BLAKE2b-256 checksum How to use checksums |
28716c67156080bdf3821a8e9256791d6fe1f0d93cd0a5a0a9779ad14fea2611
|
| 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.0a2-cp311-abi3-win_amd64.whl
| Download URL | bankai_random_forest-0.1.0a2-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 236.0 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
8e4bc6c731b969a91a14ce20295a970730039c0cf7e33e867af90a80dc00767d
|
|
BLAKE2b-256 checksum How to use checksums |
611daea7575c34fad0ec663048202eb624868f36c04eacfd970697ac0fd40585
|
| 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.0a2-cp311-abi3-manylinux_2_28_x86_64.whl
| Download URL | bankai_random_forest-0.1.0a2-cp311-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 329.8 kB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
16ea0cd7711388df00001ec6a384324c6adf24f05d731da473dcec2381356138
|
|
BLAKE2b-256 checksum How to use checksums |
e4a890b7a592ee122baac103adf73c80ede5dc844d60b331807aa3df326f26b0
|
| 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.0a2-cp311-abi3-manylinux_2_28_aarch64.whl
| Download URL | bankai_random_forest-0.1.0a2-cp311-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 309.2 kB |
| Tags | CPython 3.11 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
7ffbadccbe3172609d683109d4b3568774af9d44275804f3176b7818d93fcc06
|
|
BLAKE2b-256 checksum How to use checksums |
59b083d79ec7f5cdf73d9432d1b7285a92370597996b73f1158066ce4327872d
|
| 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.0a2-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | bankai_random_forest-0.1.0a2-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 290.6 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
230656800ffeef909685ef6888393c006a1b06b855b729bb08f559e7b63e2ed8
|
|
BLAKE2b-256 checksum How to use checksums |
4b23543f4b98282dedfbaeff2f3fbc41ceb6b1befab074ec9e42e2903c05b460
|
| 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.0a2-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | bankai_random_forest-0.1.0a2-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 310.8 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
6377aa0581f0c1d07783a76502fd9896034ac7171dc7ce7c378a6fee0511a39d
|
|
BLAKE2b-256 checksum How to use checksums |
e9f88db1955a905b32d9db7a4aa78231d831376163b96bd6ba0b57a60faea874
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|