Skip to contents

reduce_majority() makes a reducer for ensemble() that returns the output whose value occurs most often. It is the default reducer.

Usage

reduce_majority(field = NULL, tie_breaker = "first")

Arguments

field

The output field to vote on. With NULL, the first field.

tie_breaker

"first" picks, among tied values, the one that occurs first; "random" picks one at random.

Value

A function function(outputs, weights = NULL) for the reduce_fn argument of ensemble().

Details

Values are compared as strings. If the ensemble has weights, each vote counts with its module's weight. The reducer returns the whole output of the first module that gave the winning value.

Examples

vote <- reduce_majority(field = "sentiment")
vote(list(
  list(sentiment = "positive", confidence = 0.6),
  list(sentiment = "negative", confidence = 0.9),
  list(sentiment = "positive", confidence = 0.8)
))
#> $sentiment
#> [1] "positive"
#> 
#> $confidence
#> [1] 0.6
#>