Skip to contents

Represents a loss function for regression or classification tasks.

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 of `c("score", "probability")`).

fun

(`function` or `list`)
The loss function itself. Can be a single function (for single input type) or a named list of functions for different input types.

Methods


Method new()

Creates a new instance of this [R6][R6::R6Class] 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

(`function` or `list`)
The loss function. Can be a single function or a named list of functions for different input types (e.g., list(score = function(r) ..., probability = function(pi) ...)).

input_default

(`character(1)`)
Default input scale (`"score"` or `"probability"`).

input_supported

(`character()`)
Character vector of supported input scales. Must contain `input_default`.


Method get_fun()

Get the loss function for a specific input type.

Usage

LossFunction$get_fun(input_type = self$input_default)

Arguments

input_type

(`character(1)`)
The input type: `"score"` or `"probability"`.

Returns

A function for the specified input type.


Method clone()

The objects of this class are cloneable with this method.

Usage

LossFunction$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.