Skip to contents

metric_field_match() makes a metric that compares several fields of the prediction with the columns of the same names in the expected row. Values must be exactly equal (numbers may differ in storage type only).

Usage

metric_field_match(fields, require_all = TRUE)

Arguments

fields

Names of the fields to compare.

require_all

If TRUE (the default), every field must match; if FALSE, one match is enough.

Value

A function function(prediction, expected) returning TRUE or FALSE. A field missing from either side is an error.

Examples

both <- metric_field_match(c("city", "country"))
row <- data.frame(question = "Where is the Louvre?", city = "Paris", country = "France")
both(list(city = "Paris", country = "France"), row)
#> [1] TRUE
both(list(city = "Paris", country = "Belgium"), row)
#> [1] FALSE

either <- metric_field_match(c("city", "country"), require_all = FALSE)
either(list(city = "Paris", country = "Belgium"), row)
#> [1] TRUE