cv_densemlp: Cross-validate a densemlp model

View source: R/cv.R

cv_densemlpR Documentation

Cross-validate a densemlp model

Description

Fits densemlp() on each of folds training splits and evaluates it on the held-out fold via densemlp_metrics().

Usage

cv_densemlp(
  x,
  y,
  task = c("auto", "regression", "binary", "multiclass", "survival", "count"),
  folds = 5L,
  seed = 1L,
  ncores = 1L,
  verbose = FALSE,
  weights = NULL,
  ...
)

Arguments

x

Predictor data.frame or matrix.

y

Outcome vector.

task

"auto" infers the task from y, as in densemlp(). Pass "survival" explicitly for a survival outcome.

folds

Number of cross-validation folds.

seed

Random seed for fold assignment; fold k fits with seed = seed + k.

ncores

Number of cores used to fit folds in parallel (see densemlp()'s ncores).

verbose

Print per-fold progress.

weights

Optional non-negative case weights, one per row. Each fold is fitted with its training rows' weights (see densemlp()) and scored with weighted metrics on its held-out rows (see densemlp_metrics()), which gives importance-weighted cross-validation under covariate shift.

...

Additional arguments passed to densemlp() for every fold (e.g. hidden_units, epochs, lr).

Value

A list of class densemlp_cv with fold_metrics (one row per fold), summary (mean and SD per metric across folds), and task.

Examples

set.seed(1)
x <- data.frame(a = rnorm(60), b = rnorm(60))
y <- x$a - 0.5 * x$b + rnorm(60, sd = 0.1)
cv <- cv_densemlp(x, y, folds = 3, epochs = 20, hidden_units = c(8))
cv$summary

densemlp documentation built on Nov. 3, 2026, 1:09 a.m.