Prediction of test data using ordinal forest.
# S3 method for ordfor
predict(object, newdata, ...)
object of class ordfor
. See function ordfor
.
data.frame. Data frame containing new data.
further arguments passed to or from other methods.
predict.ordfor
returns an object of class ordforpred
.
An object of class "ordforpred
" is a list containing the following components:
vector of length nrow(newdata)
. Factor-valued test data predictions.
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.
Hornung R. (2020) Ordinal Forests. Journal of Classification 37, 4<U+2013>17. <10.1007/s00357-018-9302-x>.
# 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, 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)
# }
Run the code above in your browser using DataLab