predict.ordfor {ordinalForest} | R 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 |
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 |
classprobs |
predicted class probabilities. Only provided, if the performance function based on the ranked probability score was used, while training the ordinal forest (see |
References
Hornung R. (2020) Ordinal Forests. Journal of Classification 37, 4–17. <doi: 10.1007/s00357-018-9302-x>.
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)