predict.bnns {bnns} | R Documentation |
Predict Method for "bnns"
Objects
Description
Generates predictions from a fitted Bayesian Neural Network (BNN) model.
Usage
## S3 method for class 'bnns'
predict(object, newdata = NULL, ...)
Arguments
object |
An object of class |
newdata |
A matrix or data frame of new input data for which predictions are required. If |
... |
Additional arguments (currently not used). |
Details
This function uses the posterior distribution from the Stan model in the bnns
object to compute predictions for the provided input data.
Value
A matrix/array of predicted values(regression)/probabilities(classification) where first dimension corresponds to the rows of newdata
or the training data if newdata
is NULL
. Second dimension corresponds to the number of posterior samples. In case of out_act_fn = 3
, the third dimension corresponds to the class.
See Also
Examples
# Example usage:
data <- data.frame(x1 = runif(10), x2 = runif(10), y = rnorm(10))
model <- bnns(y ~ -1 + x1 + x2,
data = data, L = 1, nodes = 2, act_fn = 2,
iter = 1e1, warmup = 5, chains = 1
)
new_data <- data.frame(x1 = runif(5), x2 = runif(5))
predictions <- predict(model, newdata = new_data)
print(predictions)