50% off: Unlimited data and AI learning.
State of Data and AI Literacy Report 2025

ordinalForest (version 1.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.

yforestpredmetric

vector of length nrow(newdata). Numeric test data predictions: Result of applying the regression forest forestfinal returned by ordfor.

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, ndiv=80, nbest=5)
# NOTE: ndiv=80 is not enough!! In practice, ndiv=1000 (default value) or a higher
# number should be used.

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

par(mfrow=c(1,2)) 
plot(preds$yforestpredmetric, as.numeric(preds$ypred))
plot(pnorm(preds$yforestpredmetric), as.numeric(preds$ypred), xlim=c(0,1))
par(mfrow=c(1,1))

# }

Run the code above in your browser using DataLab