Description Usage Arguments Details Value Note Author(s) References See Also Examples
Kernel PCA is a nonlinear generalization of principal component analysis.
1 2 3 4 5 6 7 8 |
x |
either: a data matrix, a kernel matrix of class |
theta |
the inverse kernel bandwidth parameter for the Gaussian kernel. |
... |
Currently not used. |
The data can be passed to the kPCA
function in a matrix
and the Gaussian kernel (via the gaussKern
function) is used to map the data to the high-dimensional feature space where the principal components are computed. The bandwidth parameter theta
can be supplied to the gaussKern
function, else a default value is used. Alternatively, the Gaussian kernel matrix of class "kern"
can be supplied to the kPCA
function directly. In addition, kPCA
also supports input in the form of a kernel matrix of class "kernelMatrix"
(in package kernlab) thus allowing for other kernel functions.
An object of class "kPCA"
including:
KPCs |
The original data projected on the principal components. |
Es |
the corresponding eigenvalues. |
Vecs |
a matrix containing principal component vectors (column wise). |
K |
a kernel matrix of class |
theta |
if Gaussian kernel was calculated, this is the bandwidth parameter used in its calculation. |
x |
if supplied, the original data matrix. |
The predict function can be used to embed new data on the new space
K. Domijan
Schoelkopf B., A. Smola, K.-R. Mueller : Nonlinear component analysis as a kernel eigenvalue problem. Neural Computation 10, 1299-1319.
gaussKern
kpca
(in package kernlab)
kernelMatrix
(in package kernlab)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | data(iris)
testset <- sample(1:150,20)
train <- as.matrix(iris[-testset,-5])
test <- as.matrix(iris[testset,-5])
# make training set kernel
gk <- gaussKern(train)
Ktrain <- gk$K
image(Ktrain)
# make testing set kernel
gk2 <- gaussKern(train, test, gk$theta)
Ktest <- gk2$K
# make training set kernel using kernelMatrix from library kernlab.
library(kernlab)
kfunc <- laplacedot(sigma = 1)
Ktrain2 <- kernelMatrix(kfunc, train)
image(Ktrain2)
# make testing set kernel using kernelMatrix {kernlab}
Ktest2 <- kernelMatrix(kfunc, test, train)
# Do KPCA:
kpcData <- kPCA(train)
kpcKern <- kPCA(Ktrain)
kpcKern2 <- kPCA(Ktrain2)
# plot the data projection on the principal components
pairs(kpcData$KPCs[ , 1 : 3], col = iris[-testset, 5])
# proportion of variance explained by each PC
plot(kpcData$Es/sum(kpcData$Es), xlab = "PC", ylab = "Proportion of variance")
# embed data from the testing set on the new space:
KPCpred1 <- predict(kpcData, test)
KPCpred2 <- predict(kpcKern, Ktest)
KPCpred3 <- predict(kpcKern2, Ktest2)
#plot the test data projection on the principal components
pairs(KPCpred3[ , 1 : 3], col = iris[testset, 5])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.