The create_toolset function takes names of predefined tools and generates a list of wrapper functions for Precision-Recall curve calculations.

create_usrtool(
  tool_name,
  func,
  calc_auc = TRUE,
  store_res = TRUE,
  x = NA,
  y = NA
)

Arguments

tool_name

A single string to specify the name of a user-defined tool.

func

A function to calculate a Precision-Recall curve and the AUC. It should take an element of the test dataset generated by create_testset as an argument. It also should return a list with three elements - 'x', 'y', and 'auc' that represent calculated recall and precision values plus the AUC score. See create_example_func for an example.

calc_auc

A Boolean value to specify whether the AUC score should be calculated.

store_res

A Boolean value to specify whether the calculated curve is retrieved and stored.

x

Set pre-calculated recall values.

y

Set pre-calculated precision values.

Value

A list of R6 tool objects.

See also

create_toolset to create a predefined tool set. create_testset for testset. create_example_func to create an example function.

Examples

## Create a new tool interface called "xyz"
efunc <- create_example_func()
toolset1 <- create_usrtool("xyz", efunc)
toolset1
#> $xyz
#> 
#>     === Tool interface ===
#> 
#>     Tool name:            xyz 
#>     Calculate AUC score:  Yes
#>     Store results:        Yes
#>     Prediction performed: No
#>     Available methods:    call(testset, calc_auc, store_res)
#>                           get_toolname()
#>                           set_toolname(toolname)
#>                           get_setname()
#>                           set_setname(setname)
#>                           get_result()
#>                           get_x()
#>                           get_y()
#>                           get_auc()
#> 
#> 

## Example function with a correct argument
testset <- create_usrdata("bench", scores = c(0.1, 0.2), labels = c(1, 0))
retf <- efunc(testset[[1]])
retf
#> $x
#> [1] 0.0 0.5 1.0
#> 
#> $y
#> [1] 0.0 0.5 1.0
#> 
#> $auc
#> [1] 0.5
#>