forked from neurodata/SPORF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunOOB.R
More file actions
25 lines (21 loc) · 705 Bytes
/
RunOOB.R
File metadata and controls
25 lines (21 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#' Predict class labels on out-of-bag observations using a single tree.
#'
#' This is the base function called by OOBPredict.
#'
#' @param X an n sample by d feature matrix (preferable) or data frame which was used to train the provided forest.
#' @param tree a tree from a forest returned by RerF.
#'
#' @return out prediction matrix used by OOBPredict
#'
RunOOB <- function(X, tree) {
n.all <- nrow(X)
num.classes <- ncol(tree$ClassProb)
# Get OOB samples
X <- X[tree$ind, , drop = FALSE]
# Predict OOB samples
predictions <- RunPredict(X, tree)
# Create a matrix for all of samples
out <- matrix(0, nrow = n.all, ncol = num.classes)
out[tree$ind, ] <- predictions
return(out)
}