computeForestLeafIndices | R Documentation |
Compute and return a vector representation of a forest's leaf predictions for every observation in a dataset.
The vector has a "row-major" format that can be easily re-represented as
as a CSR sparse matrix: elements are organized so that the first n
elements
correspond to leaf predictions for all n
observations in a dataset for the
first tree in an ensemble, the next n
elements correspond to predictions for
the second tree and so on. The "data" for each element corresponds to a uniquely
mapped column index that corresponds to a single leaf of a single tree (i.e.
if tree 1 has 3 leaves, its column indices range from 0 to 2, and then tree 2's
leaf indices begin at 3, etc...).
computeForestLeafIndices(
model_object,
covariates,
forest_type = NULL,
forest_inds = NULL
)
model_object |
Object of type |
covariates |
Covariates to use for prediction. Must have the same dimensions / column types as the data used to train a forest. |
forest_type |
Which forest to use from 1. BART
2. BCF
3. ForestSamples
|
forest_inds |
(Optional) Indices of the forest sample(s) for which to compute leaf indices. If not provided,
this function will return leaf indices for every sample of a forest.
This function uses 0-indexing, so the first forest sample corresponds to |
List of vectors. Each vector is of size num_obs * num_trees
, where num_obs = nrow(covariates)
and num_trees
is the number of trees in the relevant forest of model_object
.
X <- matrix(runif(10*100), ncol = 10)
y <- -5 + 10*(X[,1] > 0.5) + rnorm(100)
bart_model <- bart(X, y, num_gfr=0, num_mcmc=10)
computeForestLeafIndices(bart_model, X, "mean")
computeForestLeafIndices(bart_model, X, "mean", 0)
computeForestLeafIndices(bart_model, X, "mean", c(1,3,9))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.