Skip to main content

Distributional Random Forests with different split metrics, test statistics and a Rust backend

Project description

drforest logo

drforest

PyPI CI Python License

drforest is a Python and Rust implementation of distributional random forests. A fitted forest estimates a conditional distribution as sparse weights over the training responses, then derives means, quantiles, CDFs, and distributional scores from the same estimate.

The package supports scalar and multivariate responses. Split search is Rust-backed and offers CART, Gaussian maximum mean discrepancy (MMD), adaptive and anisotropic MMD variants, and sliced Wasserstein separation.

Installation

Install the published package from PyPI:

python -m pip install drforest

Python 3.11 through 3.14 are supported. Binary wheels are published for Linux, macOS, and Windows on supported architectures; pip falls back to the source distribution when no compatible wheel is available.

Quick start

The estimator accepts ordinary one-dimensional regression targets. By default, it uses distribution-sensitive MMD splitting.

import numpy as np

from drforest import DistributionalRandomForest

rng = np.random.default_rng(0)
X = rng.normal(size=(500, 4))
y = X[:, 0] + (0.5 + np.abs(X[:, 1])) * rng.normal(size=500)

X_train, X_test = X[:400], X[400:]
y_train, y_test = y[:400], y[400:]

forest = DistributionalRandomForest(
    criterion="mmd",
    n_estimators=20,
    subsample=0.5,
    min_samples_leaf=5,
    honesty_fraction=0.5,
    colsample=0.7,
    max_cutpoints=32,
    random_state=0,
).fit(X_train, y_train)

mean = forest.predict(X_test)
quantiles = forest.predict_quantiles(X_test, [0.1, 0.5, 0.9])
cdf = forest.predict_cdf(X_test, [-1.0, 0.0, 1.0])

assert mean.shape == (100,)
assert quantiles.shape == (100, 3)
assert cdf.shape == (100, 3)

For a two-dimensional response array with shape (n_samples, n_outputs), predict returns (n_test, n_outputs). Quantile and CDF predictions return (n_test, n_outputs, n_values).

Prediction interface

  • predict(X) returns the conditional mean.
  • predict_quantiles(X, quantiles) returns marginal conditional quantiles.
  • predict_cdf(X, thresholds) evaluates marginal conditional CDFs.
  • predict_weights(X) returns the sparse conditional weight matrix.

The prediction methods retain the training responses during fit; callers do not need to pass them again.

Split criteria

Pass a built-in name through criterion:

Name Split geometry Built-in configuration
"mmd" or "mmd_rff" Gaussian MMD 128 random Fourier features, median bandwidth
"cart" Multivariate mean separation No additional configuration
"anisotropic_mmd" Coordinatewise-bandwidth MMD 128 random Fourier features
"adaptive_mmd" Adaptive-frequency MMD 128 pooled, 32 selected features
"sliced_wasserstein" Sliced Wasserstein distance 128 projections

If neither criterion nor criterion_factory is supplied, "mmd" is used. An explicit criterion name takes precedence when both are supplied.

Research and custom targets

The sparse weight matrix remains the core representation for custom targets, metrics, shrinkage, and criterion experiments:

from drforest.metrics import mean_crps
from drforest.targets import weighted_mean, weighted_quantile

weights = forest.predict_weights(X_test)
mean = weighted_mean(weights, forest.y_train_)
quantiles = weighted_quantile(weights, forest.y_train_, [0.1, 0.5, 0.9])
score = mean_crps(weights, forest.y_train_, y_test[:, None])

For a custom or specially configured split criterion, provide a factory that receives the validated two-dimensional training responses once:

from drforest import DistributionalRandomForest
from drforest.criteria import MmdRffCriterion
from drforest.features.rff import fixed_bandwidth

forest = DistributionalRandomForest(
    criterion_factory=lambda y: MmdRffCriterion.from_data(
        y,
        n_features=512,
        bandwidth_rule=fixed_bandwidth(1.0),
    ),
    n_estimators=5,
    max_cutpoints=32,
    random_state=0,
).fit(X_train, y_train)

Statistical scope

Version 0.2.0 is a research release. The core implementation is tested, but the public API may still change. The current fixed-fraction subsampling interface is intended for prediction and benchmarking; it does not claim the inference-valid regime required by the asymptotic forest theory. Missing-value handling is not implemented.

The accompanying characterization note is available as a repository PDF. It studies when distributional splitting helps, compares the implemented criteria, and gives a finite-node analysis of mean versus kernel-mean split signal. An arXiv link and formal citation will be added after the note is posted.

Design

forest structure -> sparse conditional weights -> targets and scores

This keeps split geometry separate from downstream estimation. A criterion can change without changing mean, quantile, CDF, or scoring implementations, and the same fitted forest can serve multiple targets.

Trees support honest structure/leaf sample splitting, explicit per-tree and per-node random-number streams, row subsampling, feature subsampling, and a shared candidate-cutpoint cap. MMD bandwidths are configured once from the full training response; random Fourier frequencies are resampled per node.

Benchmarks and paper

Study entry points live in benchmarks/studies:

pixi run python benchmarks/studies/run_synthetic_splitting.py
pixi run python benchmarks/studies/run_real_benchmark.py \
  --datasets diabetes \
  --criteria cart mmd_rff \
  --honesty-fractions 0.5 0.0

Generated datasets and result files are intentionally not tracked. Tables, figures, LaTeX sources, and the compiled note are committed under paper.

Development

Install the development environment and pre-commit hooks with:

git clone https://github.com/silaskoemen/drforest.git
cd drforest
pixi install
pixi run build-rust
pixi run setup

Before submitting a change, run:

pixi run lint
pixi run pytest
pixi run build-wheel
pixi run check-wheel

Security issues should be reported through SECURITY.md.

Citation

A citation for the characterization note will be added after its arXiv release. Until then, cite the repository and the specific release used so the code and results remain reproducible.

License

drforest is released under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drforest-0.2.0.tar.gz (45.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

drforest-0.2.0-cp314-cp314-win_amd64.whl (267.2 kB view details)

Uploaded CPython 3.14Windows x86-64

drforest-0.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (433.9 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

drforest-0.2.0-cp314-cp314-macosx_11_0_arm64.whl (382.2 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

drforest-0.2.0-cp314-cp314-macosx_10_12_x86_64.whl (388.3 kB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

drforest-0.2.0-cp313-cp313-win_amd64.whl (267.1 kB view details)

Uploaded CPython 3.13Windows x86-64

drforest-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (433.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

drforest-0.2.0-cp313-cp313-macosx_11_0_arm64.whl (381.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

drforest-0.2.0-cp313-cp313-macosx_10_12_x86_64.whl (388.0 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

drforest-0.2.0-cp312-cp312-win_amd64.whl (267.1 kB view details)

Uploaded CPython 3.12Windows x86-64

drforest-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (434.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

drforest-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (382.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

drforest-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl (388.0 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

drforest-0.2.0-cp311-cp311-win_amd64.whl (268.1 kB view details)

Uploaded CPython 3.11Windows x86-64

drforest-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (435.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

drforest-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (383.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

drforest-0.2.0-cp311-cp311-macosx_10_12_x86_64.whl (389.5 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

File details

Details for the file drforest-0.2.0.tar.gz.

File metadata

  • Download URL: drforest-0.2.0.tar.gz
  • Upload date:
  • Size: 45.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for drforest-0.2.0.tar.gz
Algorithm Hash digest
SHA256 82069b56d9ea6aba69425c1b7a60acdbeadcc88c144a62e89510cca419e7534a
MD5 b2a32a848cf59ab44a1da6fd5c20d8c3
BLAKE2b-256 b72eb745c2c44d2b09dd156482a2b3089b2c209a9f7488baf9473378113f9f15

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0.tar.gz:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: drforest-0.2.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 267.2 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for drforest-0.2.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 ded35e6388ae1fc610b08acdb9679e77b97746c0fed7f6254f98b58ad8ecb2ab
MD5 cee22332fb29870a2bf282eb1525869e
BLAKE2b-256 5b1076abe3ec77caedbed5186c958fc07667e625c027eee9ce66f4eddae9357e

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp314-cp314-win_amd64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9f07a8650310247bc85a25452cb8600eb04f867d9b2bbe966bc9121880af0f2a
MD5 1c8001234819bacb1806ed4d6426f143
BLAKE2b-256 f0c0ffe1139b82c8075bed38eee5fdf3bd1821a8d23ffe695759f04c517ea3b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drforest-0.2.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e527d9c139b06e757d865314c93dd2e86ca8c2c57672ef09943c26240f48963c
MD5 1851ba80c0dcb13e1e07d55817647170
BLAKE2b-256 bde16a48a6e225836b0fa8e07fed220ec5330e033042393312bc8a684365ac45

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.2.0-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 31344a8979dbb7d28d08b24d254c4461fd102e935d246359fd5a6cab991b4a49
MD5 4fc932949d4780ee9479cfb61f485628
BLAKE2b-256 74cc019fc566d6b7b7fae29a281610f2dc236269a82c7ae4a556195da9eae893

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp314-cp314-macosx_10_12_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: drforest-0.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 267.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for drforest-0.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 31ba2b05fdafb50e630426dc4432c6c0525c6db77edbdd91802481ae70520a12
MD5 81cd772ed25e4132a92922dddf2e334b
BLAKE2b-256 324684fbbdf1a7b482d5fe654671a42f4135e32a88bb4793085a62a6b533584c

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp313-cp313-win_amd64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d4806b2e2f3337dbf14d2518258bacf0b0db2de3b8a3d2fb01c4874b524da14c
MD5 e423902de6eae4f41f55582b5bd54fb4
BLAKE2b-256 76d9dcef430c6c7c80373235a127c86bdda23aafc220024c8ee74a16f5250861

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drforest-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5229302a5188c54142e8a662d9eac9cb348eb6d0823548fea6a9aec4e9d0bdab
MD5 239d9e6ea3cd9bfc8d680a0ce58117aa
BLAKE2b-256 e2c859fa615e46e1d43be9ed5b8893a3184cc8471192193321d66e842bcf9fb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.2.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 83b37d479259d38dd3b0caad5979254e3474a2b58bc3d1dbb029f7b3dac26cbb
MD5 bd2ead84d1c96efcc8bbec15241e4a1e
BLAKE2b-256 59331774ed05c33ef451f7cd304643d2004175f9ad75bd8b2f8e01c28368b47c

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: drforest-0.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 267.1 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for drforest-0.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3f5b3736b1065acb95aecb3885db9caf8d2244502991410629a1ca7ce82bd507
MD5 a3f5825225ec8ed8684d2f8ea0c06d9a
BLAKE2b-256 064f635726a4017f9c1a7ca86039bd90ebcfae0a414d743c00d20a33502c2c23

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp312-cp312-win_amd64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5c8f7f5734c4b25dfc78ddf7a2b43bef7554100fc3c2e436b5e960ee14de4bc9
MD5 454ffbdc98b9b3f321db8f7db82316f6
BLAKE2b-256 88fd66048affa6229928e83f651cec3ca2c2388fd5fee0df93849e86440e4a33

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drforest-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 986229cb0fe31a94c99bb1cac6b8909807b96334d3839d67177c619b9c95571d
MD5 1cf3e9b4efc27a37c4eb81676cb86949
BLAKE2b-256 0b4d5b7f27432feaa7439b77637ef7eec92cae5cf490ab0716cc7c3540d4dd38

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b4bb308587f3b96751d5aa7914933c32ecd6121ae92e3109e722081679899f61
MD5 3caced9df86d1a50e4d241f21ca0026c
BLAKE2b-256 ee72aba388ff1755822373a229f3a66d2f3b958a046c4be2b460803f024bccb2

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: drforest-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 268.1 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for drforest-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 db0edc6f3b52cd4e18a30e946f3f00f055f6b591cbe9f77e3b62aa5c3245f0a6
MD5 a0971cbb6dd5049278690987a089b06e
BLAKE2b-256 42bf662c296b5c6c6d3a2fd5b5f3fe979409315c1f9711043f286f0dd5511d78

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp311-cp311-win_amd64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e0979d2a7e6337321e409d317aa66d02097f4dd0d8d165ddae73f15f681c8076
MD5 2d5842a9fc4391ec59cba872eb8fa07e
BLAKE2b-256 a8d089577b05c97aa462ee868bf3691aad3f6a0d54da50ebfb4130d7354d0f75

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drforest-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a9d2570ff4e8315a7009d2b630d6a6bbc5daeb00c82bc39abc9672bd9289fb34
MD5 1f517ac8764995dcc705dde4be28e51d
BLAKE2b-256 305d1df6a43002c32951c9ab068d6da15641904fcd2bb1c37e7c86e06c499a0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drforest-0.2.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for drforest-0.2.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 05c4207abbc3a0b6d6d2dfa71498c8101db6799732004b3799fcd7ce5ee2aab6
MD5 131cdbe8cdcde5a1b12344830c80fb8c
BLAKE2b-256 367b53094f8a018cf5e63bc0308a9dce6c094313209fd68ab9fa0880576a17ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for drforest-0.2.0-cp311-cp311-macosx_10_12_x86_64.whl:

Publisher: build.yml on silaskoemen/drforest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page