predict.ODRF {ODRF} | R Documentation |
predict based on an ODRF object
Description
Prediction of ODRF for an input matrix or data frame.
Usage
## S3 method for class 'ODRF'
predict(object, Xnew, type = "response", weight.tree = FALSE, ...)
Arguments
object |
An object of class ODRF, the same created by the function |
Xnew |
An n by d numeric matrix (preferable) or data frame. The rows correspond to observations and columns correspond to features. Note that if there are NA values in the data 'Xnew', which will be replaced with the average value. |
type |
One of |
weight.tree |
Whether to weight the tree, if |
... |
Arguments to be passed to methods. |
Value
A set of vectors in the following list:
-
response
: the predicted values of the new data. -
prob
: matrix of class probabilities (one column for each class and one row for each input). Ifobject$split
ismse
, a vector of tree weights is returned. -
tree
: It is a matrix where each column is a prediction for each tree.
References
Zhan, H., Liu, Y., & Xia, Y. (2022). Consistency of The Oblique Decision Tree and Its Random Forest. arXiv preprint arXiv:2211.12653.
See Also
Examples
# Classification with Oblique Decision Random Forest
data(seeds)
set.seed(221212)
train <- sample(1:209, 80)
train_data <- data.frame(seeds[train, ])
test_data <- data.frame(seeds[-train, ])
forest <- ODRF(varieties_of_wheat ~ ., train_data,
split = "entropy", parallel = FALSE,ntrees = 50
)
pred <- predict(forest, test_data[, -8], weight.tree = TRUE)
# classification error
(mean(pred != test_data[, 8]))
# Regression with Oblique Decision Random Forest
data(body_fat)
set.seed(221212)
train <- sample(1:252, 80)
train_data <- data.frame(body_fat[train, ])
test_data <- data.frame(body_fat[-train, ])
forest <- ODRF(Density ~ ., train_data, split = "mse", parallel = FALSE,
ntrees = 50, TreeRandRotate=TRUE)
pred <- predict(forest, test_data[, -1])
# estimation error
mean((pred - test_data[, 1])^2)