Loss function
LossFunction.RdRepresents a loss function for regression or classification tasks.
Details
Loss functions are expected to be vectorized and to accept a single numeric argument representing the input on the chosen scale:
"score": residualsy_true - y_predfor regression, or signed marginsy_true * f(x)for binary classification."probability": predicted probabilities for the positive class. Visualizers obtain the loss fory = 0by evaluating the function at1 - p.
The returned value must be a numeric vector of losses with the same length as
the input. Additional optional parameters can be encoded via closures and are
configurable through lss(), which wraps the stored functions with the
supplied arguments.
Public fields
id(
character(1))
Identifier for the loss function.label(
character(1))
Label for the loss function.task_type(
character(1))
Task type:"regr"or"classif".input_default(
character(1))
The natural input scale for the loss:"score"or"probability".input_supported(
character())
All input scales this loss can be expressed on (subset ofc("score", "probability")).fun(
functionorlist)
The loss function itself. Provide either a vectorized closure matching the active input scale or a named list of such closures keyed by"score"and / or"probability".
Methods
Method new()
Creates a new instance of this R6 class.
Usage
LossFunction$new(
id,
label,
task_type,
fun,
input_default = "score",
input_supported = c("score")
)Arguments
id(
character(1))
Identifier for the loss function.label(
character(1))
Label for the loss function.task_type(
character(1))
Task type:"regr"or"classif".fun(
functionorlist)
The loss function. Supply a vectorized closure matching the active input scale or a named list of closures keyed by"score"/"probability".input_default(
character(1))
Default input scale ("score"or"probability").input_supported(
character())
Character vector of supported input scales. Must containinput_default.