Skip to main content

python bindings for C++ generalized random forests (grf)

Project description

actions travis rtd pypi pyversions

skgrf provides scikit-learn compatible Python bindings to the C++ random forest implementation, grf, using Cython.

The latest release of skgrf uses version 1.2.0 of grf.

skgrf is still in development. Please create issues for any discrepancies or errors. PRs welcome.

Installation

skgrf is available on pypi and can be installed via pip:

pip install skgrf

Estimators

  • GRFBoostedRegressor

  • GRFCausalRegressor

  • GRFInstrumentalRegressor

  • GRFLocalLinearRegressor

  • GRFQuantileRegressor

  • GRFRegressor

  • GRFSurvival

Usage

GRFRegressor

The GRFRegressor predictor uses grf’s RegressionPredictionStrategy class.

from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from skgrf.ensemble import GRFRegressor

X, y = load_boston(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y)

rfr = GRFRegressor()
rfr.fit(X_train, y_train)

predictions = rfr.predict(X_test)
print(predictions)
# [31.81349144 32.2734354  16.51560285 11.90284392 39.69744341 21.30367911
#  19.52732937 15.82126562 26.49528961 11.27220097 16.02447197 20.01224404
#  ...
#  20.70674263 17.09041289 12.89671205 20.79787926 21.18317924 25.45553279
#  20.82455595]

GRFQuantileRegressor

The GRFQuantileRegressor predictor uses grf’s QuantilePredictionStrategy class.

from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from skgrf.ensemble import GRFQuantileRegressor

X, y = load_boston(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y)

gqr = GRFQuantileRegressor(quantiles=[0.1, 0.9])
gqr.fit(X_train, y_train)

predictions = gqr.predict(X_test)
print(predictions)
# [[21.9 50. ]
# [ 8.5 24.5]
# ...
# [ 8.4 18.6]
# [ 8.1 20. ]]

License

skgrf is licensed under GPLv3.

Development

To develop locally, it is recommended to have asdf, make and a C++ compiler already installed. After cloning, run make setup. This will setup the grf submodule, install python and poetry from .tool-versions, install dependencies using poetry, copy the grf source code into skgrf, and then build and install skgrf in the local virtualenv.

To format code, run make fmt. This will run isort and black against the .py files.

To run tests and inspect coverage, run make test.

To rebuild in place after making changes, run make build.

To create python package artifacts, run make dist.

To build and view documentation, run make docs.

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

skgrf-0.0.1.tar.gz (1.7 MB view hashes)

Uploaded Source

Built Distributions

skgrf-0.0.1-cp39-cp39-manylinux1_x86_64.whl (2.4 MB view hashes)

Uploaded CPython 3.9

skgrf-0.0.1-cp39-cp39-manylinux1_i686.whl (2.4 MB view hashes)

Uploaded CPython 3.9

skgrf-0.0.1-cp39-cp39-macosx_10_15_x86_64.whl (2.4 MB view hashes)

Uploaded CPython 3.9 macOS 10.15+ x86-64

skgrf-0.0.1-cp38-cp38-manylinux1_x86_64.whl (2.4 MB view hashes)

Uploaded CPython 3.8

skgrf-0.0.1-cp38-cp38-manylinux1_i686.whl (2.4 MB view hashes)

Uploaded CPython 3.8

skgrf-0.0.1-cp38-cp38-macosx_10_15_x86_64.whl (2.4 MB view hashes)

Uploaded CPython 3.8 macOS 10.15+ x86-64

skgrf-0.0.1-cp37-cp37m-manylinux1_x86_64.whl (2.4 MB view hashes)

Uploaded CPython 3.7m

skgrf-0.0.1-cp37-cp37m-manylinux1_i686.whl (2.4 MB view hashes)

Uploaded CPython 3.7m

skgrf-0.0.1-cp37-cp37m-macosx_10_15_x86_64.whl (2.4 MB view hashes)

Uploaded CPython 3.7m macOS 10.15+ x86-64

skgrf-0.0.1-cp36-cp36m-manylinux1_x86_64.whl (2.4 MB view hashes)

Uploaded CPython 3.6m

skgrf-0.0.1-cp36-cp36m-manylinux1_i686.whl (2.4 MB view hashes)

Uploaded CPython 3.6m

skgrf-0.0.1-cp36-cp36m-macosx_10_15_x86_64.whl (2.4 MB view hashes)

Uploaded CPython 3.6m macOS 10.15+ x86-64

Supported by

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