predict.bnns: Predict Method for '"bnns"' Objects

View source: R/predict_bnns.R

predict.bnnsR 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 "bnns", typically the result of a call to bnns.default.

newdata

A matrix or data frame of new input data for which predictions are required. If NULL, predictions are made on the training data used to fit the model.

...

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

bnns, print.bnns

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)


bnns documentation built on April 3, 2025, 6:12 p.m.