Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

🔥 Bankai Random Forest

Alpha 16 prepares an opt-in virtual exact-column backend for Bankai Boruta. Ordinary classifier fits retain their current storage; AMD runtime/RSS acceptance is pending. See unreleased changes.

PyPI Latest Release Package Status Python versions uv managed Downloads License: GPL-3.0-or-later CI Dependency security Coverage GitHub Release PyPI deployment GitHub stars

BankaiRF is a high-performance Random Forest engine powered by a native Rust core. By leveraging LightGBM-style histograms for continuous feature pre-processing, it delivers fast and efficient training while maintaining full compatibility with the familiar scikit-learn estimator API. The Rust core is based on a maintained fork of XRF, the engine behind FRU.

⚠️ BankaiRF is currently in Alpha. APIs and serialized models are subject to change.

Install

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

python -m pip install bankai-random-forest

Quick start

This example uses the Covertype forest-cover dataset, which has 581,012 rows and 54 named features. It samples 100,000 rows with seed 2077, then treats cover type 2 as the positive class and all other cover types as the negative class. The dataset is provided by scikit-learn and downloaded on first use. Dataset details

import pandas as pd
from sklearn.datasets import fetch_covtype
from sklearn.metrics import f1_score, roc_auc_score
from sklearn.model_selection import train_test_split

from bankai_random_forest import BankaiRandomForestClassifier

covertype = fetch_covtype(as_frame=True)
X = covertype.data
y = (covertype.target == 2).astype("int8")

X, _, y, _ = train_test_split(
    X, y, train_size=100_000, random_state=2077, stratify=y
)

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=2077, stratify=y
)

model = BankaiRandomForestClassifier(
    n_estimators=40,
    criterion="gini",
    max_depth=20,
    max_leaf_nodes=511,
    min_samples_leaf=5,
    max_features=None,
    bootstrap=True,
    max_samples=0.8,
    n_jobs=-1,
    random_state=2077,
    importance_type="permutation", # Native permutation importance
    max_bins=63, # Enable histogram binning
)
model.fit(X_train, y_train)

predictions = model.predict(X_test)
positive_class = list(model.classes_).index(1)
probabilities = model.predict_proba(X_test)[:, positive_class]
print(f"F1: {f1_score(y_test, predictions):.3f}")
print(f"ROC-AUC: {roc_auc_score(y_test, probabilities):.3f}")

importances = pd.Series(model.feature_importances_, index=X.columns, name="importance")
print(importances.sort_values(ascending=False).head(10))

The pandas DataFrame keeps the 54 original feature names, so the feature importances are labeled with names such as Elevation, Aspect, and Slope.

Classifier reference

BankaiRandomForestClassifier follows scikit-learn's estimator pattern. The defaults and parameter meanings are listed here; behavior marked as a Bankai limitation is intentionally called out because it differs from scikit-learn.

from bankai_random_forest import BankaiRandomForestClassifier

model = BankaiRandomForestClassifier(
    n_estimators=100,
    criterion="gini",
    max_depth=None,
    min_samples_split=2,
    min_samples_leaf=1,
    min_weight_fraction_leaf=0.0,
    max_features="sqrt",
    max_leaf_nodes=None,
    min_impurity_decrease=0.0,
    bootstrap=True,
    oob_score=False,
    n_jobs=None,
    random_state=None,
    verbose=0,
    warm_start=False,
    class_weight=None,
    ccp_alpha=0.0,
    max_samples=None,
    monotonic_cst=None,
    importance_type="gain",
    max_bins=None,
    binning_strategy="exact_sort",
    bin_sample_size=200_000,
    binning_seed=6,
    extra_trees=False,
    extra_trees_backend="exact",
    extra_seed=6,
)
Parameter Default Description
n_estimators 100 Number of trees in the forest.
criterion "gini" Split criterion: "gini", "entropy", or "log_loss". entropy and log_loss use the same entropy criterion.
max_depth None Maximum tree depth. None uses Bankai's internal depth cap of 512; otherwise use an integer of at least 1.
min_samples_split 2 Minimum samples required to split a node. Accepts an integer of at least 2 or a fraction in (0, 1] of the training rows.
min_samples_leaf 1 Minimum samples required at a leaf. Accepts an integer of at least 1 or a fraction in (0, 1] of the training rows.
min_weight_fraction_leaf 0.0 Minimum fraction of the total sample weight required at a leaf; must be between 0 and 0.5.
max_features "sqrt" Features considered at each split: "sqrt", "log2", None (all features), an integer count, or a fraction in (0, 1].
max_leaf_nodes None Maximum number of leaves per tree. None means no explicit leaf limit; otherwise use an integer of at least 1.
min_impurity_decrease 0.0 A split is made only when its impurity decrease is at least this non-negative value.
bootstrap True Whether each tree is trained on a bootstrap sample. Required for out-of-bag scoring and permutation importance.
oob_score False If true, calculate out-of-bag predictions and accuracy; a callable can provide a custom score. Requires bootstrap=True.
n_jobs None Number of worker threads. None uses one worker, a positive integer sets the count, and negative values follow joblib CPU-count rules (-1 uses all available CPUs). 0 is invalid.
random_state None Seed or RandomState controlling bootstrap samples, feature selection, and other randomized steps. Set it for repeatable fits.
verbose 0 Non-negative integer verbosity level. Values above zero print fit progress.
warm_start False Accepted for estimator compatibility. Currently, calling fit again rebuilds the forest instead of adding trees to the previous fit.
class_weight None None, "balanced", "balanced_subsample", a class-to-weight dictionary, or (for multioutput targets) a list of dictionaries, one per output.
ccp_alpha 0.0 Non-negative cost-complexity pruning strength. Larger values prune more of each tree.
max_samples None Number or fraction of rows sampled for each tree. Accepts an integer count or a fraction in (0, 1]; only valid with bootstrap=True. None samples the full training size.
monotonic_cst None One constraint per input feature: -1 decreasing, 0 unconstrained, or 1 increasing. Currently supported only for binary single-output classification.
importance_type "gain" How feature_importances_ is calculated: "gain", "split", "permutation", or "shap" (mean absolute native TreeSHAP). Permutation requires bootstrap=True. SHAP supports shap_mode="sampled" (up to shap_sample_size=1000 training rows), "all", or "explicit"; explicit mode exposes shap_importances(X).
max_bins None None uses exact split search. An integer from 2 to 255 enables histogram split search for Random Forest. Must be None with the default Extra Trees backend; required with the experimental "binned" backend.
binning_strategy "exact_sort" How histogram cut points are found: "exact_sort", "sampled_sort", "exact_select", or "sampled_select". Applies only when max_bins is set.
bin_sample_size 200_000 Positive maximum number of rows used per feature by sampled histogram strategies. Applies only when max_bins is set.
binning_seed 6 Seed for row sampling in "sampled_sort" and "sampled_select". Independent of random_state; the default preserves the historical sampled rows.
extra_trees False Evaluate one random threshold per sampled feature. Original values are used by the default "exact" backend. Classification only.
extra_trees_backend "exact" "exact" uses original values. Experimental "binned" requires extra_trees=True, integer max_bins, and dense input; uses column-major bins and one-pass binary split statistics.
extra_seed 6 Seed offset for random threshold selection when extra_trees=True. Combine with random_state for repeatable forests.

extra_trees=True samples a continuous threshold uniformly between the node's original observed minimum and maximum for each feature considered. With the default extra_trees_backend="exact", max_bins must be None; setting an integer raises ValueError. Opt into the experimental binned backend explicitly to use bins. Features are sampled without replacement; constants are inherited by descendants, and search continues when needed to find a valid partition. Bootstrap uses effective sample weights as sampling probabilities and counts distinct sampled rows for leaf limits. Gain importance is normalized within each tree before aggregation. This option currently applies to classification. See the campaign notes for validation and profiling.

binning_seed only affects sampled binning strategies and does not change tree bootstrap or feature-sampling randomness. It lets repeated experiments vary the rows used to build histogram cut points independently of the forest's random_state.

Call fit(X, y, sample_weight=None) to train. sample_weight accepts one finite, non-negative weight per row. The fitted estimator exposes scikit-learn-style methods including predict, predict_proba, and predict_log_proba, plus classes_, feature_importances_, n_features_in_, and feature_names_in_ when the input has named columns.

predict_proba returns one probability array for a single target and a list of arrays for multioutput targets. monotonic_cst is not supported for multioutput classification. oob_score=True computes accuracy; to use another metric, pass a callable with signature metric(y_true, y_pred).

Experimental binned Extra Trees

model = BankaiRandomForestClassifier(
    extra_trees=True,
    extra_trees_backend="binned",
    max_bins=63,
    bootstrap=True,
    n_jobs=6,
    random_state=42,
)
model.fit(X, y)

This backend stores dense bins by column and, for binary classification, accumulates per-feature bin statistics in one pass. It does not build the global histogram caches used by Random Forest. Sparse training input is rejected without densification. Prediction, OOB, gain importance, SHAP and pickle restoration retain the backend. Multiclass inputs use the generic random split scan on column-major bins.

The default is extra_trees_backend="exact", not None. It uses original values and requires max_bins=None. The example above explicitly enables column-major bins and uses the existing exact_sort preparation default on all training rows. To opt into sampled preparation, set binning_strategy="sampled_select" and bin_sample_size=20_000. Both preparation options include layout conversion in fit.

Binning changes the distribution of random thresholds and can reduce ranking quality. Three paired local fraud repetitions with 500,000 rows, 500 features, 100 trees, bootstrap enabled and six jobs produced these medians:

Extra Trees configuration Fit seconds Feature-ranking AP Informative features in top 24
Original values, default backend 24.14 0.6866 14
Column bins, full exact_sort 11.82 0.6775 15
Column bins, full exact_select 10.51 0.6633 14
Column bins, sampled_select, 20,000 rows 8.77 0.6393 15

These are screening results for one synthetic scenario, not a quality guarantee. AP here evaluates informative-feature ranking, not classification precision-recall. The standard binning_strategy="exact_sort" and bin_sample_size=200_000 defaults are unchanged. The sample-size limit applies only to sampled strategies.

The layout conversion is included in fit time and temporarily allocates another one-byte-per-cell matrix. Random Forest (extra_trees=False) retains row-major bins; extra_trees_backend="binned" is rejected for that mode.

Regressor

BankaiRandomForestRegressor follows the RandomForestRegressor parameter defaults and supports single and multioutput regression. Regression currently delegates training and prediction to scikit-learn; max_bins, binning_strategy, and bin_sample_size are accepted for API consistency but do not affect regression training. The supported criteria are squared_error, absolute_error, and poisson; Poisson targets must be nonnegative and have a positive sum. With importance_type="permutation", set oob_score=True; importance is the decrease in R² from aggregated OOB predictions.

Development

To build and run the project locally, install Git, Python 3.11 or newer, a stable Rust toolchain, and uv. On Windows, install the Rust MSVC build tools; on macOS, install the Xcode command-line tools.

Clone the repository and create the locked development environment:

git clone https://github.com/breno-jesus-fernandes/bankai-random-forest.git
cd bankai-random-forest
uv python install 3.11
uv sync --locked --no-install-project
uv run maturin develop --release --locked

Run the Python and Rust test suites from the repository root:

uv run pytest -q
uv run cargo test --workspace --locked

Benchmark scripts use an additional dependency group. Install it when needed with uv sync --locked --group benchmark. All commands use the versions recorded in uv.lock and Cargo.lock.

Contributors are expected to follow the Code of Conduct. See the contribution guide for the fork and pull request workflow, local checks, and maintainer review expectations.

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

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.0a18
File Size Uploaded Provenance Actions
bankai_random_forest-0.1.0a18.tar.gz 1.3 MB With provenance Details for bankai_random_forest-0.1.0a18.tar.gz

Built distributions (wheels)

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

Total release size: 3.3 MB

Release files / bankai_random_forest-0.1.0a18.tar.gz

Download URL bankai_random_forest-0.1.0a18.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
09649e01fbd7e546335d3f554043a948ed523824ffad79dad12f78fd6d24ac6e
BLAKE2b-256 checksum
How to use checksums
41d8af03e6b3b8a251d3dc284f0a9fe25c78b83fa8628cb59bfc096f507335fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / bankai_random_forest-0.1.0a18-cp311-abi3-win_amd64.whl

Download URL bankai_random_forest-0.1.0a18-cp311-abi3-win_amd64.whl
Size 339.7 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
fed3b9b67f02de783141e3e01c3ed9267ed9e3f401424c331bec5b5b99cc9589
BLAKE2b-256 checksum
How to use checksums
c32f33380bb5ed54e27102416261d600711f1185b5ddf21b3725f0cf2838abff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / bankai_random_forest-0.1.0a18-cp311-abi3-manylinux_2_28_x86_64.whl

Download URL bankai_random_forest-0.1.0a18-cp311-abi3-manylinux_2_28_x86_64.whl
Size 435.1 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
902a904ea86e07f75d0ecaee235245ddba9a856ba3e969dc43f6e530dafe34be
BLAKE2b-256 checksum
How to use checksums
fecff75f465dac77d698cf441f10a505d863b2703da8d3d70f21c221d787b5fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / bankai_random_forest-0.1.0a18-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL bankai_random_forest-0.1.0a18-cp311-abi3-manylinux_2_28_aarch64.whl
Size 399.9 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
dd740dc2f446e0046fcf181189f969e51446ca57908d5110a36e490a1b6b3cfb
BLAKE2b-256 checksum
How to use checksums
d8473b3b878dae0247785bfa430e34f741a038e4cec18b37140454dd3a1621c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / bankai_random_forest-0.1.0a18-cp311-abi3-macosx_11_0_arm64.whl

Download URL bankai_random_forest-0.1.0a18-cp311-abi3-macosx_11_0_arm64.whl
Size 378.2 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4de9113bb7ff781ef13d88f926e1003feb2bfc8dc99df96bf9705109fbd1711d
BLAKE2b-256 checksum
How to use checksums
4845c1a5d1136e1b87fb69dc00c75193255eaa147efaa8e2e377a43064816e3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / bankai_random_forest-0.1.0a18-cp311-abi3-macosx_10_12_x86_64.whl

Download URL bankai_random_forest-0.1.0a18-cp311-abi3-macosx_10_12_x86_64.whl
Size 415.9 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
0a5bca9b753afa4682535d4ad5801bcbf873b7a26cada2aae5ba46deb94fda6f
BLAKE2b-256 checksum
How to use checksums
1a67fbfff2ce10a965d093a798a57c2a0bd13642e0c3ca815d5df297101090ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Security for bankai-random-forest 0.1.0a18

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for bankai_random_forest-0.1.0a18.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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