Skip to contents

This is the abstract base class for task objects like PredictionClassif or PredictionRegr.

Prediction objects store the following information:

  1. The row ids of the test set

  2. The corresponding true (observed) response.

  3. The corresponding predicted response.

  4. Additional predictions based on the class and predict_type. E.g., the class probabilities for classification or the estimated standard error for regression.

Note that this object is usually constructed via a derived classes, e.g. PredictionClassif or PredictionRegr.

S3 Methods

  • as.data.table(rr)
    Prediction -> data.table::data.table()
    Converts the data to a data.table::data.table().

  • c(..., keep_duplicates = TRUE)
    (Prediction, Prediction, ...) -> Prediction
    Combines multiple Predictions to a single Prediction. If keep_duplicates is FALSE and there are duplicated row ids, the data of the former passed objects get overwritten by the data of the later passed objects.

See also

Other Prediction: PredictionClassif, PredictionRegr

Public fields

data

(named list())
Internal data structure.

task_type

(character(1))
Required type of the Task.

task_properties

(character())
Required properties of the Task.

predict_types

(character())
Set of predict types this object stores.

man

(character(1) | NULL)
String in the format [pkg]::[topic] pointing to a manual page for this object. Defaults to NA, but can be set by child classes.

Active bindings

row_ids

(integer())
Vector of row ids for which predictions are stored.

truth

(any)
True (observed) outcome.

missing

(integer())
Returns row_ids for which the predictions are missing or incomplete.

weights

(numeric())
Vector of measure weights, obtained from the weights_measure column of the Task if present. This is NULL if no weights are present.

extra

(named list())
Additional per-observation data stored in the prediction object, e.g., quantities returned by the learner that are not covered by a predict type. Each element is a vector with one entry per observation, i.e., of the same length as row_ids. Names must be unique and may not clash with the names of the standard prediction columns (e.g., "row_ids", "truth", "response", or "weights"). The extra data is subset by $filter(), combined row-wise by c(), and appended as additional columns by data.table::as.data.table(). This is NULL if no extra data is present.

raw

(any)
Raw prediction object from the upstream model. Only available if the learner's predict_raw flag was set to TRUE and the learner implementation supports it. The object is stored as-is, without validation or subsetting during filtering. When multiple predictions are combined via c(), the individual raw objects are collected into a list().

Methods


Prediction$format()

Helper for print outputs.

Usage

Prediction$format(...)

Arguments

...

(ignored).


Prediction$print()

Printer.

Usage

Prediction$print(...)

Arguments

...

(ignored).


Prediction$help()

Opens the corresponding help page referenced by field $man.

Usage

Prediction$help()


Prediction$score()

Calculates the performance for all provided measures Task and Learner may be NULL for most measures, but some measures need to extract information from these objects. Note that the predict_sets of the measures are ignored by this method, instead all predictions are used.

Usage

Prediction$score(
  measures = NULL,
  task = NULL,
  learner = NULL,
  train_set = NULL
)

Arguments

measures

(Measure | list of Measure | NULL)
Measure(s) to calculate.

task

(Task).

learner

(Learner).

train_set

(integer()).

Returns

Prediction.


Prediction$obs_loss()

Calculates the observation-wise loss via the Measure's obs_loss method. Returns a data.table() with the columns of the matching Prediction object plus one additional numeric column for each measure, named with the respective measure id. If there is no observation-wise loss function for the measure, the column is filled with NA_real_ values. Note that some measures such as RMSE, do have an $obs_loss, but they require an additional transformation after aggregation, in this example taking the square-root.

Usage

Prediction$obs_loss(measures = NULL)

Arguments

measures

(Measure | list of Measure | NULL)
Measure(s) to calculate.


Prediction$filter()

Filters the Prediction, keeping only predictions for the provided row_ids. This changes the object in-place, you need to create a clone to preserve the original Prediction.

Usage

Prediction$filter(row_ids)

Arguments

row_ids

integer()
Row indices.

Returns

self, modified.


Prediction$clone()

The objects of this class are cloneable with this method.

Usage

Prediction$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.