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 and other array types

With the matching extra installed, you can pass pandas / polars data frames or jax arrays directly; they are converted to the appropriate R object. This is required for rbartpackages.bartMachine, whose X argument must be an R data frame.

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.