Quickstart¶
Each wrapped R package has its own submodule. Import the one you need and call
the wrapper class like the corresponding R function; arguments are converted to
R, and the fitted R object’s components become Python attributes (with .
replaced by _).
import numpy as np
from rbartpackages import BART3
x_train = np.random.randn(100, 5)
y_train = x_train[:, 0] + 0.1 * np.random.randn(100)
bart = BART3.gbart(x_train=x_train, y_train=y_train, ndpost=200)
y_pred = bart.predict(x_train) # shape (ndpost, n)
Argument names use Python underscores in place of R dots: pass x_train for
the R argument x.train. The same pattern works for the other wrappers, e.g.
rbartpackages.BART, rbartpackages.dbarts, rbartpackages.bartMachine, and
rbartpackages.missBART.
Data frames¶
R dataframes are converted to/from pandas dataframes on the Python side. If
polars[pyarrow] is installed, dataframes are returned as polars dataframes,
and both pandas and polars dataframes are accepted as input.
R documentation¶
The original R documentation of each function is appended to the corresponding
wrapper class docstring, so help(BART3.gbart) shows the upstream
reference.