View source: R/170_Decomposition.R
| reconstruct | R Documentation |
Encode data with a fitted decomposition and decode it back, giving the
rank-k approximation of the input in its original units and column layout.
reconstruct(decom, x, execution_config = NULL, verbosity = 1L)
decom |
|
x |
Tabular data (data.frame, data.table, or tibble): Data to
reconstruct. Its columns must match those |
execution_config |
Optional |
verbosity |
Integer: Verbosity level. |
The round trip apply_decomp leaves half-done. The reconstruction is x
with everything outside the first k components removed, i.e. a denoised
x. The residual, x - reconstruct(decom, x), is what the decomposition
could not represent: rowMeans(residual^2) scores how anomalous each case
is, and colMeans(residual^2) shows which variables the decomposition fails
to capture.
Available for algorithms whose invertible trait is TRUE; see
decomposition_traits. tSNE, UMAP and Isomap embed without an inverse, so
there is no map back for them at all.
The reconstruction is in the units of the data as it was passed to decomp,
with any centering or scaling the backend applied internally undone, so it
can be compared with x directly. Columns the fit did not decompose (when
decom@config@features is set) pass through unchanged and column order is
preserved, so the result lines up cell for cell with x.
A data.frame with the same columns as x, holding the
reconstruction of the decomposed features.
EDG
x <- exc(iris, "Species")
iris_pca <- decomp(x, algorithm = "PCA", config = setup_PCA(k = 2L))
reconstructed <- reconstruct(iris_pca, x)
# What the two components could not represent, per case:
head(rowMeans((as.matrix(x) - as.matrix(reconstructed))^2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.