Exports the estimator component of an mlr3 learner to ONNX format for cross-language deployment. Supports xgboost and glmnet learners.
Details
ONNX export is currently supported for: - xgboost: via native xgboost save + Python conversion (most reliable) - glmnet: via coefficient extraction (linear models)
For xgboost, this function exports the native .xgb format. A separate Python script can convert to ONNX. For glmnet, coefficients are exported as JSON.
For other learners, only the preprocessing manifest is exported. Use vetiver for R-based deployment of these models.
Examples
if (FALSE) { # \dontrun{
if (requireNamespace("jsonlite", quietly = TRUE) &&
requireNamespace("mlr3learners", quietly = TRUE) &&
requireNamespace("xgboost", quietly = TRUE)) {
# Train xgboost model
task <- tsk("iris")
learner <- lrn("classif.xgboost", nrounds = 50)
learner$train(task)
# Export to ONNX-compatible format
export_onnx(learner, "model.onnx", task)
}
} # }