R interface to Python's GPopt.MLOptimizer. A convenience layer on top of [GPOpt()] specialized for cross-validated tuning of a scikit-learn estimator class: you provide training data, an estimator *class* (not an instance), and a parameter configuration (bounds/transforms/dtypes), and `$optimize()` runs the cross-validated Bayesian search for you.

MLOptimizer(
  scoring = "accuracy",
  cv = 5L,
  n_jobs = NULL,
  n_init = 10L,
  n_iter = 90L,
  seed = 3137L,
  venv_path = "./venv"
)

Arguments

scoring

scikit-learn scoring string, e.g. `"accuracy"`, `"r2"`, `"neg_mean_squared_error"`

cv

number of cross-validation folds

n_jobs

number of jobs to run in parallel during cross-validation (`NULL` uses scikit-learn's default)

n_init

number of points in the initial design

n_iter

number of iterations of the optimizer

seed

integer random seed

venv_path

path to the Python virtual environment created with `uv` (see the package README for setup instructions)

Value

A Python `GPopt.MLOptimizer` object. Useful members (accessed with `$`):

  • `$optimize(X_train, y_train, estimator_class, param_config, verbose = 2L)`

  • `$get_best_parameters(apply_transforms = TRUE)`

  • `$get_best_score()`

  • `$create_optimized_estimator()`

  • `$fit_optimized_estimator(X_train, y_train)`

Examples

if (FALSE) { # \dontrun{
sklearn <- get_sklearn(venv_path = "./venv")
RandomForestClassifier <- sklearn$ensemble$RandomForestClassifier

X <- as.matrix(iris[, 1:4])
y <- as.integer(iris$Species) - 1L

mlopt <- MLOptimizer(scoring = "accuracy", cv = 5L, n_iter = 90L, venv_path = "./venv")

param_config <- list(
  n_estimators = list(bounds = c(10, 300), dtype = "int"),
  max_depth    = list(bounds = c(1, 20), dtype = "int")
)

mlopt$optimize(
  X_train = X, y_train = y,
  estimator_class = RandomForestClassifier(),
  param_config = param_config,
  verbose = 2L
)
mlopt$get_best_parameters()
mlopt$get_best_score()
} # }