Prediction method for class oml.

# 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.

Value

Matrix of predictions.

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.

References

  • Di Francesco, R. (2023). Ordered Correlation Forest. arXiv preprint arXiv:2309.08755.

Author

Riccardo Di Francesco

Examples

## Generate synthetic data.
set.seed(1986)

data <- generate_ordered_data(100)
sample <- data$sample
Y <- sample$Y
X <- sample[, -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))
#>         P(Y=1)    P(Y=2)     P(Y=3)     P(Y=1)    P(Y=2)     P(Y=3)
#> [1,] 0.4208750 0.4629083 0.11621667 0.29341958 0.6154394 0.09114097
#> [2,] 0.4666167 0.4243833 0.10900000 0.33450837 0.5539351 0.11155656
#> [3,] 0.1424000 0.3843583 0.47324167 0.07811249 0.3029698 0.61891769
#> [4,] 0.6361333 0.3146500 0.04921667 0.63353157 0.3260411 0.04042733
#> [5,] 0.4543667 0.3177833 0.22785000 0.29489112 0.4336047 0.27150420
#> [6,] 0.6192250 0.3248750 0.05590000 0.37336853 0.5365585 0.09007298