The Prediction object returned by learners that were trained on a
TaskTorch.
Because a TaskTorch can represent very different learning problems, this class does not
prescribe much about how truth, response, prob and se are stored.
This is defined by the task's prediction encoder, where you need to ensure that the first
dimension indexes the observations.
Within that, an element may be an atomic vector, a matrix(), an array() of any
dimensionality, a data.table or a lazy_tensor.
truth is whatever task$truth() returned – a vector for one target, a data.table for
several, a lazy_tensor for a lazy tensor column, and nothing at all for a task without a
target.
When a prediction is converted to a data.table, which is e.g. used for the printer,
the conversion depends on the type of the object.
A prob matrix spreads into one column per class, the way it does for a classification
prediction.
Everything else that is wider than one value per observation becomes a single column whose cells
hold that observation's own array, printed as its shape – <array[3]> for a response matrix
with three columns, <array[3x224x224]> for a prob with a class dimension and two spatial
ones.
Missing Predictions
Only a response with a single value per observation can report a missing prediction, so
$missing can only be TRUE for scalars and is always FALSE for parially missing predictions.
Super class
mlr3::Prediction -> PredictionTorch
Active bindings
response(any)
The predicted response.prob(any)
The predicted probabilities.se(any)
The standard errors of the prediction.lazy_tensor(
lazy_tensorordata.tableof them)
The output of the network, for the predict type"lazy_tensor".
Methods
PredictionTorch$new()
Creates a new instance of this R6 class.
Usage
PredictionTorch$new(
task = NULL,
row_ids = task$row_ids,
truth = if (!is.null(task)) task$truth(row_ids),
response = NULL,
prob = NULL,
se = NULL,
lazy_tensor = NULL,
weights = NULL,
check = TRUE
)Arguments
task(
TaskTorch)
The task that was predicted on. Used to extract the defaultrow_idsand thetruth.row_ids(
integer())
The row ids of the predicted observations.truth(any)
The ground truth, i.e. whattask$truth()returned.response(any)
The predicted response.prob(any)
The predicted probabilities.se(any)
The standard errors of the prediction.lazy_tensor(
lazy_tensorordata.tableof them)
The output of the network, see the predict type"lazy_tensor"ofLearnerTorch. A network with more than one head produces one column per head.weights(
numeric()orNULL)
The measure weights of the predicted observations, i.e. theweights_measurecolumn of the task.mlr3fills this in, so it rarely has to be passed by hand.check(
logical(1))
Whether to check the consistency of the prediction data.
Examples
d = data.frame(x = rnorm(10), y1 = rnorm(10), y2 = rnorm(10))
task = as_task_torch(d, target = c("y1", "y2"))
PredictionTorch$new(task, response = as.matrix(d[, c("y1", "y2")]))
#>
#> ── <PredictionTorch> for 10 observations: ──────────────────────────────────────
#> row_ids truth.y1 truth.y2 response
#> 1 -0.55369938 0.46815442 <array[2]>
#> 2 0.62898204 0.36295126 <array[2]>
#> 3 2.06502490 -1.30454355 <array[2]>
#> --- --- --- ---
#> 8 -0.05260191 -0.01595031 <array[2]>
#> 9 0.54299634 -0.82678895 <array[2]>
#> 10 -0.91407483 -1.51239965 <array[2]>