predict.oml {ocf}R Documentation

Prediction Method for oml Objects

Description

Prediction method for class oml.

Usage

## S3 method for class 'oml'
predict(object, data = NULL, ...)

Arguments

object

An oml object.

data

Data set of class data.frame. It must contain the same covariates used to train the base learners. If data is NULL, then object$X is used.

...

Further arguments passed to or from other methods.

Details

If object$learner == "l1", then model.matrix is used to handle non-numeric covariates. If we also have object$scaling == TRUE, then data is scaled to have zero mean and unit variance.

Value

Matrix of predictions.

Author(s)

Riccardo Di Francesco

See Also

multinomial_ml, ordered_ml

Examples


## Load data from orf package.
set.seed(1986)

library(orf)
data(odata)
odata <- odata[1:100, ] # Subset to reduce elapsed time.

y <- as.numeric(odata[, 1])
X <- as.matrix(odata[, -1])

## Training-test split.
train_idx <- sample(seq_len(length(y)), floor(length(y) * 0.5))

y_tr <- y[train_idx]
X_tr <- X[train_idx, ]

y_test <- y[-train_idx]
X_test <- X[-train_idx, ]

## Fit ordered machine learning on training sample using two different learners.
ordered_forest <- ordered_ml(y_tr, X_tr, learner = "forest")
ordered_l1 <- ordered_ml(y_tr, X_tr, learner = "l1")

## Predict out of sample.
predictions_forest <- predict(ordered_forest, X_test)
predictions_l1 <- predict(ordered_l1, X_test)

## Compare predictions.
cbind(head(predictions_forest), head(predictions_l1))


[Package ocf version 1.0.0 Index]