register_custom_test: Register a Custom Test Function in ValidMind

View source: R/custom_tests.R

register_custom_testR Documentation

Register a Custom Test Function in ValidMind

Description

Registers an R function as a custom test within the ValidMind testing framework, allowing it to be used as a custom metric for model validation.

Usage

register_custom_test(
  func,
  test_id = NULL,
  description = NULL,
  required_inputs = NULL
)

Arguments

func

An R function to be registered as a custom test.

test_id

A unique identifier for the test. If NULL, a default ID is generated based on the function name.

description

A description of the test. If NULL, the function's description attribute is used. Defaults to "No description" if not available.

required_inputs

A character vector specifying the required inputs for the test. If NULL, the function's formal argument names are used.

Details

The provided R function is converted into a Python callable using r_to_py. A Python class is then defined, inheriting from ValidMind's Metric class, which wraps this callable. This custom test is registered within ValidMind's test store and can be used in the framework for model validation purposes.

Value

The test store object containing the newly registered custom test.

See Also

r_to_py, import_main, py_run_string

Examples

## Not run: 
# Define a custom test function in R
my_custom_metric <- function(predictions, targets) {
  # Custom metric logic
  mean(abs(predictions - targets))
}

# Register the custom test
register_custom_test(
  func = my_custom_metric,
  test_id = "custom.mae",
  description = "Custom Mean Absolute Error",
  required_inputs = c("predictions", "targets")
)

## End(Not run)


validmind documentation built on April 4, 2025, 5:05 a.m.