predict.Treee {LDATree} | R Documentation |
Generate predictions on new data using a fitted Treee
model.
## S3 method for class 'Treee'
predict(object, newdata, type = c("response", "prob", "all"), ...)
object |
A fitted model object of class |
newdata |
A data frame containing the predictor variables. Missing values are allowed and will be handled according to the fitted tree's method for handling missing data. |
type |
A character string specifying the type of prediction to return. Options are:
|
... |
Additional arguments passed to or from other methods. |
Depending on the value of type
, the function returns:
If type = 'response'
: A character vector of predicted class labels.
If type = 'prob'
: A data frame of posterior probabilities, where each class has its own column.
If type = 'all'
: A data frame containing predicted class labels, posterior probabilities, and the predicted node indices.
Note: For factor predictors, if a level not present in the training data is
found in newdata
, it will be treated as missing and handled according to
the missingMethod
specified in the fitted tree.
fit <- Treee(datX = iris[, -5], response = iris[, 5], verbose = FALSE)
head(predict(fit, iris)) # Predicted classes
head(predict(fit, iris[, -5], type = "prob")) # Posterior probabilities
head(predict(fit, iris[, -5], type = "all")) # Full details