Learn R Programming

ordinalForest (version 2.0)

predict.ordfor: Prediction using ordinal forest objects

Description

Prediction of test data using ordinal forest.

Usage

# S3 method for ordfor
predict(object, newdata, ...)

Arguments

object

object of class ordfor. See function ordfor.

newdata

data.frame. Data frame containing new data.

...

further arguments passed to or from other methods.

Value

predict.ordfor returns an object of class ordforpred. An object of class "ordforpred" is a list containing the following components:

ypred

vector of length nrow(newdata). Factor-valued test data predictions.

classfreqtree

matrix of dimension nrow(newdata) x J. The value in the j-th column of the i-th row contains the frequency of trees that predicted class j for test observation i.

Examples

Run this code
# NOT RUN {
data(hearth)

set.seed(123)
trainind <- sort(sample(1:nrow(hearth), size=floor(nrow(hearth)*(1/2))))
testind <- setdiff(1:nrow(hearth), trainind)

datatrain <- hearth[trainind,]
datatest <- hearth[testind,]

ordforres <- ordfor(depvar="Class", data=datatrain, nsets=60, nbest=5)
# NOTE: nsets=60 is not enough, because the prediction performance of the resulting 
# ordinal forest will be suboptimal!! In practice, nsets=1000 (default value) or a 
# number should be used.

preds <- predict(ordforres, newdata=datatest)
preds
 
table(data.frame(true_values=datatest$Class, predictions=preds$ypred))

head(preds$classfreqtree)

# }

Run the code above in your browser using DataLab