Skip to contents

Computes the validation error for a given machine learning model using resampled datasets. This function fits the model to each split of the data and then collects and filters the performance metrics, specifically focusing on R-squared (rsq) for validation.

Usage

get_validation_error(model, splits, metric)

Arguments

model

A machine learning model object, expected to be compatible with the fit_resamples method from the tune package.

splits

An object containing data splits, typically generated by functions from the rsample package, used for resampling.

metric

The performance metric of interest as a string.

Value

A data frame containing the R-squared metric for each resample along with an identification of the error type as "Validation".

Examples

if (FALSE) { # \dontrun{
library(dplyr)
library(tidymodels) # assuming tidymodels includes necessary packages
data(iris)
model <- linear_reg() %>% set_engine("lm")
splits <- vfold_cv(iris, v = 5)
validation_error <- get_validation_error(model, splits)
} # }