Skip to contents

Wrap a parsnip::model_spec — e.g. parsnip::rand_forest() combined with parsnip::set_engine() — as an xplus() backend, giving the PLUS loop access to the full tidymodels engine zoo. The spec's mode is set per fit: "classification" when the target is binary (iterative pseudo-label fits), "regression" when fractional (the final fit), so the model must support both modes or parsnip::fit_xy() reports the gap. Case weights are passed as hardhat::frequency_weights() when integral and hardhat::importance_weights() otherwise; foldid is unused because parsnip specs carry no internal resampling.

Usage

xplus_backend_parsnip(spec, supports_fractional = TRUE)

Arguments

spec

A parsnip model specification produced by a model function such as parsnip::rand_forest(), parsnip::boost_tree() or parsnip::logistic_reg(), usually piped through parsnip::set_engine(). The engine must be set and its package installed.

supports_fractional

Logical scalar; declare FALSE for specs whose model lacks a regression mode (e.g. logistic_reg) so xplus() fails early with a clear message instead of at the fractional final fit.

Value

An "xplus_backend" object named parsnip:<engine>.

Details

fit_predict returns out-of-bag scores when the underlying engine stores them on the fitted object (ranger engines) and falls back to in-sample predict otherwise, so honest cutoff calibration is preserved where the engine makes it possible. Engines that consume a seed argument (ranger, xgboost, lightgbm) get one drawn from R's RNG when the spec does not set it explicitly, keeping xplus(seed = ...) reproducible. Feature importance is read from the fitted engine object when present; declare it in the spec, e.g. set_engine("ranger", importance = "impurity").

Examples

if (FALSE) { # \dontrun{
backend <- parsnip::rand_forest(trees = 500) |>
  parsnip::set_engine("ranger") |>
  xplus_backend_parsnip()
fit <- xplus(x, y, backend = backend)
} # }