Description Usage Arguments Value Class Methods Details Examples
Feature extraction by principal component analysis
1 | pca_extractor(ncomp, center = TRUE, scale = TRUE)
|
ncomp
number of principal components to extract
center
either a logical value that indicates whether variables should be centered to zero-mean, or numeric vector of center values
scale
either a logical value that indicates whether variables should be scaled to unit-variance, or numeric vector of scale values
PCAExtractor
class object
fit(x, y = NULL)
conduct principal component analysis of x
transform(x, y = NULL)
extract principal components of x
predict(x, y = NULL)
returns all principal components of x
Uses prcomp
as the backend.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | p <- pca_extractor(2, center=TRUE, scale=TRUE)
p$fit(USArrests)
p$transform(USArrests)
p$predict(USArrests)
# inv_transform partially recovers the original data
cor(as.numeric(as.matrix(USArrests)),
as.numeric(p$inv_transform(p$transform(USArrests)$x)$x))
p2 <- pca_extractor(4, center=TRUE, scale=TRUE)
p2$fit(USArrests)
p2$transform(USArrests)
p2$predict(USArrests)
# when ncomp = ncol(x), inv_transform recovers the data perfectly
cor(as.numeric(as.matrix(USArrests)),
as.numeric(p2$inv_transform(p2$transform(USArrests)$x)$x))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.