pca: Feature extraction by principal component analysis

Description Usage Arguments Value Class Methods Details Examples

Description

Feature extraction by principal component analysis

Usage

1
pca_extractor(ncomp, center = TRUE, scale = TRUE)

Arguments

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

Value

PCAExtractor class object

Class Methods

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

Details

Uses prcomp as the backend.

Examples

 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))

kota7/MLPipe documentation built on May 5, 2019, 5:53 p.m.