Learn R Programming

bigrf (version 0.1-12)

predict-methods: Predict Classes of Test Examples

Description

Predict the classes of a set of test examples using a random forest.

Usage

"predict"(object, x, y=NULL, printerrfreq=10L, printclserr=TRUE, cachepath=tempdir(), trace=0L)

Arguments

object
A random forest of class "bigcforest".
x
A big.matrix, matrix or data.frame of predictor variables. If a matrix or data.frame is specified, it will be converted into a big.matrix for computation.
y
An integer or factor vector of response variables. Test errors will be calculated only if y is specified.
printerrfreq
An integer, specifying how often error estimates should be printed to the screen. Default: error estimates will be printed every 10 trees.
printclserr
TRUE for error estimates for individual classes to be printed, in addition to the overall error estimates. Default: TRUE.
cachepath
Path to folder where data caches used in building the forest can be stored. If NULL, then the big.matrix's will be created in memory, with no disk caching; this will be suitable for small data sets. Default: tempdir().
trace
0 for no verbose output. 1 to print verbose output on prediction by trees, and a summary of the predictions. Default: 0. Due to the way %dopar% handles output, you may not see the verbose output in some GUIs like RStudio. For best results, run R from the command line in order to see all the verbose output.

Value

An object of class "bigcprediction" containing the prediction results.

Methods

signature(object = "bigcforest")
Predict classes of a set of test examples using a classification random forest.

Details

These methods copy all the trees from y into x, and calculates the error statistics and confusion matrices of the merged forest.

References

Breiman, L. (2001). Random forests. Machine learning, 45(1), 5-32.

Breiman, L. & Cutler, A. (n.d.). Random Forests. Retrieved from http://www.stat.berkeley.edu/~breiman/RandomForests/cc_home.htm.

Examples

Run this code
# Classify cars in the Cars93 data set by type (Compact, Large,
# Midsize, Small, Sporty, or Van).

# Load data.
data(Cars93, package="MASS")
x <- Cars93
y <- Cars93$Type

# Select variables with which to train model.
vars <- c(4:22)

# Run model, grow 30 trees on the first 60 examples.
forest <- bigrfc(x[1:60, ], y[1:60], ntree=30L, varselect=vars, cachepath=NULL)

# Get predictions for the remaining examples.
predictions <- predict(forest, x[-(1:60), ], y[-(1:60)], cachepath=NULL)

Run the code above in your browser using DataLab