# kpca: Kernel Principal Components Analysis In kernlab: Kernel-Based Machine Learning Lab

## Description

Kernel Principal Components Analysis is a nonlinear form of principal component analysis.

## Usage

 1 2 3 4 5 6 7 8 9 10 11 12 13 ## S4 method for signature 'formula' kpca(x, data = NULL, na.action, ...) ## S4 method for signature 'matrix' kpca(x, kernel = "rbfdot", kpar = list(sigma = 0.1), features = 0, th = 1e-4, na.action = na.omit, ...) ## S4 method for signature 'kernelMatrix' kpca(x, features = 0, th = 1e-4, ...) ## S4 method for signature 'list' kpca(x, kernel = "stringdot", kpar = list(length = 4, lambda = 0.5), features = 0, th = 1e-4, na.action = na.omit, ...)

## Arguments

 x the data matrix indexed by row or a formula describing the model, or a kernel Matrix of class kernelMatrix, or a list of character vectors data an optional data frame containing the variables in the model (when using a formula). kernel the kernel function used in training and predicting. This parameter can be set to any function, of class kernel, which computes a dot product between two vector arguments. kernlab provides the most popular kernel functions which can be used by setting the kernel parameter to the following strings: rbfdot Radial Basis kernel function "Gaussian" polydot Polynomial kernel function vanilladot Linear kernel function tanhdot Hyperbolic tangent kernel function laplacedot Laplacian kernel function besseldot Bessel kernel function anovadot ANOVA RBF kernel function splinedot Spline kernel The kernel parameter can also be set to a user defined function of class kernel by passing the function name as an argument. kpar the list of hyper-parameters (kernel parameters). This is a list which contains the parameters to be used with the kernel function. Valid parameters for existing kernels are : sigma inverse kernel width for the Radial Basis kernel function "rbfdot" and the Laplacian kernel "laplacedot". degree, scale, offset for the Polynomial kernel "polydot" scale, offset for the Hyperbolic tangent kernel function "tanhdot" sigma, order, degree for the Bessel kernel "besseldot". sigma, degree for the ANOVA kernel "anovadot". Hyper-parameters for user defined kernels can be passed through the kpar parameter as well. features Number of features (principal components) to return. (default: 0 , all) th the value of the eigenvalue under which principal components are ignored (only valid when features = 0). (default : 0.0001) na.action A function to specify the action to be taken if NAs are found. The default action is na.omit, which leads to rejection of cases with missing values on any required variable. An alternative is na.fail, which causes an error if NA cases are found. (NOTE: If given, this argument must be named.) ... additional parameters

## Details

Using kernel functions one can efficiently compute principal components in high-dimensional feature spaces, related to input space by some non-linear map.
The data can be passed to the kpca function in a matrix or a data.frame, in addition kpca also supports input in the form of a kernel matrix of class kernelMatrix or as a list of character vectors where a string kernel has to be used.

## Value

An S4 object containing the principal component vectors along with the corresponding eigenvalues.

 pcv a matrix containing the principal component vectors (column wise) eig The corresponding eigenvalues rotated The original data projected (rotated) on the principal components xmatrix The original data matrix

all the slots of the object can be accessed by accessor functions.

## Note

The predict function can be used to embed new data on the new space

## Author(s)

Alexandros Karatzoglou
[email protected]

## References

Schoelkopf B., A. Smola, K.-R. Mueller :
Nonlinear component analysis as a kernel eigenvalue problem
Neural Computation 10, 1299-1319
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.29.1366

## Examples

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 # another example using the iris data(iris) test <- sample(1:150,20) kpc <- kpca(~.,data=iris[-test,-5],kernel="rbfdot", kpar=list(sigma=0.2),features=2) #print the principal component vectors pcv(kpc) #plot the data projection on the components plot(rotated(kpc),col=as.integer(iris[-test,5]), xlab="1st Principal Component",ylab="2nd Principal Component") #embed remaining points emb <- predict(kpc,iris[test,-5]) points(emb,col=as.integer(iris[test,5]))

### Example output

[,1]          [,2]
[1,] -0.22173444 -0.0316057724
[2,] -0.21937042 -0.0329783464
[3,] -0.22924356 -0.0546422092
[4,] -0.22435285 -0.0524354167
[5,] -0.22862278 -0.0336632614
[6,] -0.21989021 -0.0387947960
[7,] -0.22584671 -0.0270511320
[8,] -0.20409190 -0.0796609744
[9,] -0.19643970 -0.0740476380
[10,] -0.18192952 -0.0590401104
[11,] -0.22873035 -0.0433163649
[12,] -0.19994043 -0.0088313526
[13,] -0.22373134 -0.0459830195
[14,] -0.21574859  0.0051351454
[15,] -0.22443076 -0.0364921526
[16,] -0.21875216 -0.0958924803
[17,] -0.21718315  0.0206466471
[18,] -0.21462911  0.0153977733
[19,] -0.21838557 -0.0007814966
[20,] -0.22456155 -0.0097064874
[21,] -0.22662766 -0.0332264356
[22,] -0.22757564 -0.0408453838
[23,] -0.22100509 -0.0126032397
[24,] -0.21911414 -0.0130588365
[25,] -0.21252662 -0.0652444704
[26,] -0.20185110 -0.0692288401
[27,] -0.22367227 -0.0227849934
[28,] -0.22668873 -0.0597659289
[29,] -0.21944931 -0.0505593072
[30,] -0.22870114 -0.0611283088
[31,] -0.21107989 -0.0574016057
[32,] -0.22788623 -0.0308707784
[33,] -0.22958774 -0.0570702550
[34,] -0.17909287 -0.0309101276
[35,] -0.21582162 -0.0641344218
[36,] -0.21965721 -0.0053234120
[37,] -0.20885253  0.0120717581
[38,] -0.22057279 -0.0298724893
[39,] -0.22231741 -0.0388543824
[40,] -0.22251797 -0.0486163882
[41,] -0.22274358 -0.0409139063
[42,] -0.22881725 -0.0414330520
[43,]  0.12203629 -0.0354116356
[44,]  0.12533390  0.1318343511
[45,]  0.13466947 -0.0790268552
[46,]  0.06140194  0.4160589250
[47,]  0.13389697  0.1190037659
[48,]  0.10734126  0.3117955251
[49,]  0.13340429  0.0730944413
[50,] -0.03785623  0.3757002098
[51,]  0.12733177  0.1156600050
[52,] -0.01135717  0.3831953902
[53,]  0.10000626  0.3086505973
[54,]  0.06541720  0.3836524288
[55,]  0.02677508  0.4100567292
[56,]  0.11747209  0.1150431431
[57,]  0.10764035  0.2830073700
[58,]  0.07140666  0.3945974361
[59,]  0.11582020  0.2313660924
[60,]  0.05112712  0.4301964691
[61,]  0.13332942  0.0987742264
[62,]  0.08449097  0.3471516097
[63,]  0.13900127  0.0932259735
[64,]  0.12516009  0.2113493910
[65,]  0.11147664  0.2325797950
[66,]  0.11982400  0.1462561021
[67,]  0.14557136 -0.0914609600
[68,]  0.12338486  0.2383537274
[69,]  0.01057286  0.4243230626
[70,]  0.03787577  0.4365446044
[71,]  0.02438339  0.4370755723
[72,]  0.06284177  0.4074826548
[73,]  0.14224649  0.0635706405
[74,]  0.09753707  0.2982352915
[75,]  0.13390971  0.0216656103
[76,]  0.10990414  0.2577866481
[77,]  0.06314242  0.4183172434
[78,]  0.08852528  0.3670681137
[79,]  0.12725315  0.1987708032
[80,]  0.07184372  0.4028794037
[81,] -0.03276453  0.3839505198
[82,]  0.08383046  0.3836497433
[83,]  0.08225918  0.3594186421
[84,]  0.10932685  0.2723493977
[85,] -0.05986438  0.3552139357
[86,]  0.08001899  0.3838789222
[87,]  0.11174014 -0.3654734979
[88,]  0.13747090  0.0521812240
[89,]  0.11840073 -0.4325993754
[90,]  0.14374831 -0.1948761506
[91,]  0.13290479 -0.3379905093
[92,]  0.06727044 -0.4858350686
[93,]  0.09421112 -0.4569959064
[94,]  0.12894853 -0.2879452651
[95,]  0.08821729 -0.4722447849
[96,]  0.14611329 -0.1419672109
[97,]  0.14839262 -0.1289547547
[98,]  0.13955148 -0.3114673402
[99,]  0.12844978  0.0928693487
[100,]  0.12808093 -0.0362672116
[101,]  0.13993545 -0.2199152150
[102,]  0.14627739 -0.2155713841
[103,]  0.04551314 -0.4447461247
[104,]  0.12619740  0.1319695080
[105,]  0.12562341 -0.3973616979
[106,]  0.12662309  0.1177905292
[107,]  0.05862641 -0.4655183716
[108,]  0.14633742  0.0329187203
[109,]  0.13217400 -0.3541834904
[110,]  0.11033895 -0.4323922318
[111,]  0.14382545  0.0771450225
[112,]  0.14426407  0.0504600511
[113,]  0.11778385 -0.3679063211
[114,]  0.09888820 -0.4486233330
[115,]  0.05170736 -0.4404592369
[116,]  0.13931634 -0.2606084288
[117,]  0.13215034 -0.0725998569
[118,]  0.08112285 -0.4791336293
[119,]  0.12656375 -0.2915974484
[120,]  0.13939761  0.0998772411
[121,]  0.13772856 -0.3075798739
[122,]  0.13082861 -0.3514225290
[123,]  0.13409870 -0.2485719662
[124,]  0.13747090  0.0521812240
[125,]  0.12108178 -0.4189229007
[126,]  0.12145072 -0.3827467382
[127,]  0.14008493 -0.2366008239
[128,]  0.14377571 -0.0007908873
[129,]  0.13245178 -0.2165902411
[130,]  0.14168693  0.0277001238

kernlab documentation built on May 30, 2017, 6:43 a.m.