Wraps a plain R function into a Measure that scores the predictions of a
TaskTorch.
Use msr_torch() to construct one.
See the Custom Learning Problems article for how to create and use such measures.
See also
Other Measure:
mlr_measures_torch.default
Super class
mlr3::Measure -> MeasureTorch
Methods
MeasureTorch$new()
Creates a new instance of this R6 class.
Usage
MeasureTorch$new(
id,
fun,
minimize = NA,
range = c(-Inf, Inf),
predict_type = "response",
properties = character(),
label = NA_character_,
obs_loss = NULL
)Arguments
id(
character(1))
The id of the measure.fun(
function())
The scoring function. It receives whichever of the argumentstruth,response,prob,se,lazy_tensor,prediction,task,learner,train_setandweightsit declares, and must return a single number. Asking for anything else is an error.minimize(
logical(1))
Whether a smaller score is better.NA(default) means the direction is unknown.range(
numeric(2))
The range of possible scores.predict_type(
character(1))
The predict type the measure requires:"response"(default),"prob","se"or"lazy_tensor". A measure asking for one it did not declare here still receives it, if the prediction has it.properties(
character())
Properties of the measure, seeMeasure. The"requires_task","requires_learner","requires_train_set"and"weights"properties are added automatically whenfundeclares the corresponding argument.label(
character(1))
The label of the measure.obs_loss(
function()orNULL)
The per-observation loss. Declared likefun, except thattrain_setis not available here, and if specified adds the"obs_loss"property. It must return one number per observation.
Examples
d = data.frame(x = rnorm(10), y = rnorm(10))
task = as_task_torch(d, target = "y")
measure = msr_torch("mse", function(truth, response) mean((truth - response)^2))
measure
#>
#> ── <MeasureTorch> (mse) ────────────────────────────────────────────────────────
#> • Packages: mlr3
#> • Range: [-Inf, Inf]
#> • Minimize: NA
#> • Average: macro
#> • Parameters: list()
#> • Properties: -
#> • Predict type: response
#> • Predict sets: test
#> • Aggregator: mean()