Skip to contents

Prediction of ODRF for an input matrix or data frame.

Usage

# S3 method for ODRF
predict(object, Xnew, type = "response", weight.tree = FALSE, ...)

Arguments

object

An object of class ODRF, the same created by the function ODRF.

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 response, prob or tree, indicating the type of output: predicted values, matrix of class probabilities or predicted value for each tree.

weight.tree

Whether to weight the tree, if TRUE then use the out-of-bag error of the tree as the weight. (default FALSE)

...

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). If object$split is mse, 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]))
#> [1] 0.03100775

# Regression with Oblique Decision Random Forest
# \donttest{
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)
#> [1] 3.66148e-05
# }