predict.ordfor: Prediction using ordinal forest objects

View source: R/predict.ordfor.R

predict.ordforR Documentation

Prediction using ordinal forest objects

Description

Prediction of test data using ordinal forest.

Usage

## S3 method for class '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.

classprobs

predicted class probabilities. Only provided, if the performance function based on the ranked probability score was used, while training the ordinal forest (see ordfor). Matrix of dimension nrow(newdata) x J (NA, if the ranked probability was not used while training). The value in the j-th column of the i-th row contains the predicted probability that test observation i is of class j.

References

Examples

## Not run: 
data(hearth)

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

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

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

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

head(preds$classprobs)

## End(Not run)


ordinalForest documentation built on Dec. 1, 2022, 1:25 a.m.