predict.Model | R Documentation |
Obtains the predictions using a fitted model object.
## S3 method for class 'Model'
predict(model, x, format = "list")
model |
( |
x |
( |
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 <- to_matrix(iris[, -5])
y <- iris$Species
model <- random_forest(x, y)
# Predict using the fitted model
predictions <- predict(model, x)
# Obtain the predicted values
predictions$predicted
# Obtain the predicted probabilities
predictions$probabilities
# Predict using the fitted model with data.frame format
predictions <- predict(model, x, format = "data.frame")
head(predictions)
# Multivariate analysis -----------------------------------------------------
x <- to_matrix(iris[, -c(1, 2)])
y <- iris[, c(1, 2)]
model <- generalized_linear_model(x, y)
# Predict using the fitted model
predictions <- predict(model, x)
# Obtain the predicted values of the first response variable
predictions$Sepal.Length$predicted
# Obtain the predicted values of the second response variable
predictions$Sepal.Width$predicted
# Obtain the predictions in a data.frame not in a list
predictions <- predict(model, x, 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.