predict.JRandomForest: Predict

Description Usage Arguments Value Examples

View source: R/predict.R

Description

Predict on the random forest.

Usage

1
2
3
## S3 method for class 'JRandomForest'
predict(object, newData = NULL,
  parallel = TRUE, out.of.bag = NULL, ...)

Arguments

object

A forest that was previously trained

newData

The new data containing all of the previous predictor covariates. Can be NULL if you want to use the training dataset, and object hasn't been loaded from the disk; otherwise you'll have to specify it.

parallel

A logical indicating whether multiple cores should be utilized when making the predictions. Available as an option because it's been observed that using Java's parallelStream can be unstable on some systems. Default value is TRUE; only set to FALSE if you get strange errors while predicting.

out.of.bag

A logical indicating whether predictions should be based on 'out of bag' trees; set only to TRUE if you're running predictions on data that was used in the training. Default value is TRUE if newData is NULL, otherwise FALSE.

...

Other parameters that may one day get passed onto other functions; currently not used.

Value

A list of responses corresponding with each row of newData if it's a non-regression random forest; otherwise it returns a numeric vector.

Examples

 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
26
27
28
29
30
31
# Regression Example
x1 <- rnorm(1000)
x2 <- rnorm(1000)
y <- 1 + x1 + x2 + rnorm(1000)

data <- data.frame(x1, x2, y)
forest <- train(y ~ x1 + x2, data, ntree=100, numberOfSplits = 5,
    mtry = 1, nodeSize = 5)

# Fix x2 to be 0
newData <- data.frame(x1 = seq(from=-2, to=2, by=0.5), x2 = 0)
ypred <- predict(forest, newData)

plot(ypred ~ newData$x1, type="l")

# Competing Risk Example
x1 <- abs(rnorm(1000))
x2 <- abs(rnorm(1000))

T1 <- rexp(1000, rate=x1)
T2 <- rweibull(1000, shape=x1, scale=x2)
C <- rexp(1000)
u <- pmin(T1, T2, C)
delta <- ifelse(u==T1, 1, ifelse(u==T2, 2, 0))

data <- data.frame(x1, x2)

forest <- train(CR_Response(delta, u) ~ x1 + x2, data, ntree=100,
   numberOfSplits=5, mtry=1, nodeSize=10)
newData <- data.frame(x1 = c(-1, 0, 1), x2 = 0)
ypred <- predict(forest, newData)

jatherrien/largeRCRF documentation built on Nov. 15, 2019, 7:16 a.m.