View source: R/bayesian_model_model.R
predict.BayesianModel | R Documentation |
Obtains the predictions using a fitted model object of class BayesianModel
.
## S3 method for class 'BayesianModel'
predict(model, indices, format = "list")
model |
( |
indices |
( |
format |
( |
format
is "list"
For univariate models a named list
with the element "predicted"
which
contains the predicted values is returned. For categorical variables the
returned list
includes the element "probabilities"
too with a
data.frame
of the predicted probabilities of each class.
For multivariate models a named list
is returned where there is an named
element for each response variable in the fitted model. Each element of this
list contains a inner list
in the same format as described for the
univariate case, so for categorical variables, a data.frame
with the
predicted probabilities is included too.
format
is "data.frame"
For univariate models a data.frame
with the column predicted
which
contains the predicted values. For categorical variables, a column for each
class with the predicted probability of this class is included too.
For multivariate models a data.frame
with a column for each response
variable with the predicted values of each response.
## Not run:
# Univariate analysis -------------------------------------------------------
x <- list(list(x = to_matrix(iris[, -5]), model = "BRR"))
y <- iris$Species
model <- bayesian_model(x, y, testing_indices = c(1:5, 51:55, 101:105))
# Predict using the fitted model (of the specified testing indices)
predictions <- predict(model, indices = c(1:5, 51:55, 101:105))
# Obtain the predicted values
predictions$predicted
# Obtain the predicted probabilities
predictions$probabilities
# Predict using the fitted model (with different indices)
predictions <- predict(model, indices = 1:50)
predictions$predicted
# Multivariate analysis -----------------------------------------------------
x <- list(list(x = to_matrix(iris[, -c(1, 2)]), model = "fixed"))
y <- iris[, c(1, 2)]
y[c(5, 55, 105), 1] <- NA
y[c(6, 66, 106), 2] <- NA
model <- bayesian_model(x, y, iterations_number = 1000)
# Predict using the fitted model, with different indices and data.frame
# format
predictions <- predict(model, indices = c(10, 20, 30), format = "data.frame")
head(predictions)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.