compare: Compare multiple learners with optional tuning.

View source: R/compare.R

compareR Documentation

Compare multiple learners with optional tuning.

Description

Compare multiple learners with optional tuning.

Usage

compare(
  data,
  formula,
  models,
  specs = NULL,
  resampling = cv(5),
  metrics = NULL,
  type = NULL,
  conf_level = 0.95,
  seed = NULL,
  ncores = NULL,
  tune = FALSE,
  grids = NULL,
  metric = NULL,
  ...
)

Arguments

data

Data frame.

formula

Model formula.

models

Character vector of learner ids.

specs

Optional named list of fixed specs per learner.

resampling

Resampling object from cv().

metrics

Character vector of metrics to report. When tune = TRUE, these are computed for each learner's tuned best configuration.

type

Prediction type override.

conf_level

Confidence level for learner summary intervals.

seed

Optional seed.

ncores

Optional number of CPU cores used to compare learners. NULL or 1 runs sequentially.

tune

Logical; if TRUE, run tune() for each learner before comparing.

grids

Optional tuning grids. Supply either a single data frame to reuse across learners or a named list of data frames keyed by learner id.

metric

Optimization metric used when tune = TRUE.

...

Additional arguments passed to evaluate() or tune() / fit().

Value

A funcml_compare object.

Examples

cmp <- compare(
  data = mtcars,
  formula = mpg ~ wt + hp,
  models = c("glm", "rpart"),
  resampling = cv(3, seed = 1),
  metrics = c("rmse", "mae")
)
cmp$results

funcml documentation built on Aug. 22, 2026, 5:08 p.m.