Predict: Compute class predictions for each observation in X

Description Usage Arguments Value Examples

View source: R/Predict.R

Description

Predicts the classification of samples using a trained forest.

Usage

1
2
Predict(X, forest, OOB = FALSE, num.cores = 0L, Xtrain = NULL,
  aggregate.output = TRUE, output.scores = FALSE)

Arguments

X

an n by d numeric matrix (preferable) or data frame. The rows correspond to observations and columns correspond to features of a test set, which should be different from the training set.

forest

a forest trained using the RerF function.

OOB

if TRUE then run predictions using out-of-bag samples.

num.cores

the number of cores to use while training. If NumCores=0 then 1 less than the number of cores reported by the OS are used. (NumCores=0)

Xtrain

an n by d numeric matrix (preferable) or data frame. This should be the same data matrix/frame used to train the forest, and is only required if RerF was called with rank.transform = TRUE. (Xtrain=NULL)

aggregate.output

if TRUE then the tree predictions are aggregated weighted by their probability estimates. Otherwise, the individual tree probabilities are returned. (aggregate.output=TRUE)

TODO: Remove option for aggregate output? Only options for returning aggregate predictions or probabilities

output.scores

if TRUE then predicted class scores (probabilities) for each observation are returned rather than class labels. (output.scores = FALSE)

Value

predictions an n length vector of predictions

Examples

1
2
3
4
5
6
7
8
library(rerf)
trainIdx <- c(1:40, 51:90, 101:140)
X <- as.matrix(iris[, 1:4])
Y <- as.numeric(iris[, 5])
forest <- RerF(X[trainIdx, ], Y[trainIdx], num.cores = 1L, rank.transform = TRUE)
# Using a set of samples with unknown classification
predictions <- Predict(X[-trainIdx, ], forest, num.cores = 1L, Xtrain = X[trainIdx, ])
error.rate <- mean(predictions != Y[-trainIdx])

rerf documentation built on May 2, 2019, 8:16 a.m.