skgrf

build wheels 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 2.1.0 of grf. Refer to the GRF docs for detailed references.

Installation

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

pip install skgrf

Usage

GRFForestRegressor

The GRFForestRegressor predictor uses grf’s RegressionPredictionStrategy class.

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

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

forest = GRFForestRegressor()
forest.fit(X_train, y_train)

predictions = forest.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]

GRFForestQuantileRegressor

The GRFForestQuantileRegressor predictor uses grf’s QuantilePredictionStrategy class.

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

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

forest = GRFForestQuantileRegressor(quantiles=[0.1, 0.9])
forest.fit(X_train, y_train)

predictions = forest.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.

Indices and tables