predict.mml {ocf} | R Documentation |
Prediction Method for mml Objects
Description
Prediction method for class mml
.
Usage
## S3 method for class 'mml'
predict(object, data = NULL, ...)
Arguments
object |
An |
data |
Data set of class |
... |
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
References
Di Francesco, R. (2025). Ordered Correlation Forest. Econometric Reviews, 1–17. doi:10.1080/07474938.2024.2429596.
See Also
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 multinomial machine learning on training sample using two different learners.
multinomial_forest <- multinomial_ml(Y_tr, X_tr, learner = "forest")
multinomial_l1 <- multinomial_ml(Y_tr, X_tr, learner = "l1")
## Predict out of sample.
predictions_forest <- predict(multinomial_forest, X_test)
predictions_l1 <- predict(multinomial_l1, X_test)
## Compare predictions.
cbind(head(predictions_forest), head(predictions_l1))
[Package ocf version 1.0.3 Index]