Learn R Programming

rtemis (version 1.4.3)

decomposition_metrics: Decomposition Metrics

Description

Quantify a fitted decomposition: how much of the data its components reconstruct, how redundant they are, and -- given data the fit never saw -- whether it generalizes.

Usage

decomposition_metrics(
  decom,
  x,
  new_data = NULL,
  execution_config = NULL,
  verbosity = 1L
)

Value

DecompositionMetrics object.

Arguments

decom

Decomposition object.

x

Tabular data (data.frame, data.table, or tibble): The data decom was fitted on.

new_data

Optional tabular data: Data the fit never saw. Its columns must match those decom was fitted on.

execution_config

Optional ExecutionConfig object: Threads and device for encoding and reconstructing, as in apply_decomposition(). NULL uses the host's default worker count.

verbosity

Integer: Verbosity level.

Author

EDG

Details

Which metrics are computed follows from the algorithm's traits; see decomposition_metric_traits. A metric its algorithm cannot support is NA.

The unprefixed metrics describe the fitted data, so x must be that data: they are computed against the components decom already holds. A different number of cases is an error, and x failing to match decom@data_fingerprint is reported without raising, since scoring a fit against an altered copy of its training data is a valid analysis.

decomp() already stores this on its result for the data it was fitted on, so calling this without new_data recomputes what decom@metrics holds. With new_data it computes reconstruction_gap, the difference between out-of-sample and in-sample relative reconstruction error, which indicates a decomposition that has fitted its training cases rather than their structure.

Reconstruction is measured in the units of the data as it was passed to decomp(), so the numbers are comparable across algorithms and across configurations of one algorithm. One caveat: ICA with row_norm = TRUE standardizes each case across features, and inverting that needs each case's own mean and standard deviation, taken from the data being reconstructed. Its reconstruction therefore draws on information the components do not carry, and its error is not comparable with an algorithm that reconstructs from components alone.

Examples

Run this code
x <- exc(iris, "Species")
iris_pca <- decomp(x, algorithm = "PCA", verbosity = 0L)
decomposition_metrics(iris_pca, x, verbosity = 0L)

Run the code above in your browser using DataLab