Thin extender over kernlab::kpca that performs PCA in a
feature space induced by a reproducing-kernel.
Arguments
- x
Numeric matrix or data frame of features (rows = observations).
- ...
Further arguments forwarded to
kernlab::kpca(e.g.kernel,kpar,features,th).
Value
A list with $method = "kernlab::kpca" and
$raw (a kpca S4 object with eigenvalues,
eigenvectors and the projected rotated data).
Examples
# \donttest{
if (requireNamespace("kernlab", quietly = TRUE)) {
set.seed(1)
x <- matrix(stats::rnorm(200), ncol = 4)
morie_kernel_pca(x, kernel = "rbfdot", features = 2)
}
#> $method
#> [1] "kernlab::kpca"
#>
#> $raw
#> An object of class "kpca"
#> Slot "rotated":
#> [,1] [,2]
#> [1,] 1.5859278 -1.01093357
#> [2,] -0.7330867 2.11940031
#> [3,] -0.1268089 -1.62591316
#> [4,] -3.3761357 2.72557699
#> [5,] -2.4921376 -3.85492370
#> [6,] 0.5590333 -2.47882769
#> [7,] 1.8829402 2.39901633
#> [8,] -2.0079905 3.12546672
#> [9,] -2.8033782 -1.31453766
#> [10,] 3.8876315 1.75379532
#> [11,] 0.1424867 -3.54280959
#> [12,] -1.5361400 0.19502348
#> [13,] 3.5800476 0.11457749
#> [14,] 3.0099098 -0.44459125
#> [15,] -3.1026839 2.13074700
#> [16,] 4.0239487 0.60591143
#> [17,] -1.4939840 3.39591819
#> [18,] -2.6487437 -3.42647697
#> [19,] -1.0288784 0.68015566
#> [20,] 0.5431806 -3.92821821
#> [21,] 3.1118262 0.22136556
#> [22,] -0.2128546 2.99652081
#> [23,] 1.1437805 -1.01926898
#> [24,] 1.3068408 0.80393132
#> [25,] -2.1965878 3.21830242
#> [26,] 0.5455555 0.16483647
#> [27,] 1.7288237 1.78905221
#> [28,] 4.5033727 0.51587331
#> [29,] 2.5086943 0.11071273
#> [30,] 1.7010390 2.16320920
#> [31,] -3.7753985 1.52828887
#> [32,] 1.9666544 0.78242555
#> [33,] 0.8945879 -1.84837525
#> [34,] -2.8958630 1.31005077
#> [35,] 2.9749514 -0.93588385
#> [36,] -0.5880234 -1.70037326
#> [37,] 3.6516561 -1.33121658
#> [38,] -2.2463246 0.27993687
#> [39,] -2.4355383 -0.89022809
#> [40,] -2.8907224 -0.57614987
#> [41,] -1.2935475 0.04300075
#> [42,] 2.2220832 -1.36417804
#> [43,] -2.1139165 -3.31907418
#> [44,] 1.3143664 -0.98964819
#> [45,] -1.2066590 -4.13221986
#> [46,] -1.4820941 -2.37475198
#> [47,] 2.1348648 2.99777793
#> [48,] -3.3359750 1.56847134
#> [49,] -0.3354653 2.01285076
#> [50,] -2.5652653 0.35640418
#>
#> Slot "pcv":
#> [,1] [,2]
#> [1,] 0.29309071 -0.24061746
#> [2,] -0.13547961 0.50444929
#> [3,] -0.02343518 -0.38699190
#> [4,] -0.62393382 0.64872850
#> [5,] -0.46056470 -0.91753008
#> [6,] 0.10331332 -0.58999844
#> [7,] 0.34798070 0.57100213
#> [8,] -0.37109089 0.74390830
#> [9,] -0.51808418 -0.31287982
#> [10,] 0.71846186 0.41742978
#> [11,] 0.02633255 -0.84324221
#> [12,] -0.28388956 0.04641854
#> [13,] 0.66161820 0.02727117
#> [14,] 0.55625268 -0.10581943
#> [15,] -0.57339800 0.50714998
#> [16,] 0.74365425 0.14421608
#> [17,] -0.27609883 0.80827984
#> [18,] -0.48950662 -0.81555329
#> [19,] -0.19014402 0.16188732
#> [20,] 0.10038362 -0.93497528
#> [21,] 0.57508754 0.05268835
#> [22,] -0.03933704 0.71321722
#> [23,] 0.21137875 -0.24260142
#> [24,] 0.24151344 0.19134780
#> [25,] -0.40594500 0.76600460
#> [26,] 0.10082252 0.03923357
#> [27,] 0.31949888 0.42582146
#> [28,] 0.83225521 0.12278564
#> [29,] 0.46362449 0.02635130
#> [30,] 0.31436407 0.51487647
#> [31,] -0.69772042 0.36375584
#> [32,] 0.36345168 0.18622910
#> [33,] 0.16532619 -0.43994124
#> [34,] -0.53517602 0.31181188
#> [35,] 0.54979211 -0.22275450
#> [36,] -0.10867090 -0.40471453
#> [37,] 0.67485195 -0.31684966
#> [38,] -0.41513672 0.06662921
#> [39,] -0.45010475 -0.21188774
#> [40,] -0.53422601 -0.13713237
#> [41,] -0.23905676 0.01023483
#> [42,] 0.41065673 -0.32469498
#> [43,] -0.39066676 -0.78998980
#> [44,] 0.24290423 -0.23555122
#> [45,] -0.22299915 -0.98353076
#> [46,] -0.27390149 -0.56522685
#> [47,] 0.39453816 0.71351644
#> [48,] -0.61651183 0.37331988
#> [49,] -0.06199637 0.47908889
#> [50,] -0.47407923 0.08482958
#>
#> Slot "eig":
#> Comp.1 Comp.2
#> 0.10822095 0.08402828
#>
#> Slot "kernelf":
#> new("rbfkernel", .Data = function (x, y = NULL)
#> {
#> if (!is(x, "vector"))
#> stop("x must be a vector")
#> if (!is(y, "vector") && !is.null(y))
#> stop("y must a vector")
#> if (is(x, "vector") && is.null(y)) {
#> return(1)
#> }
#> if (is(x, "vector") && is(y, "vector")) {
#> if (!length(x) == length(y))
#> stop("number of dimension must be the same on both data points")
#> return(exp(sigma * (2 * crossprod(x, y) - crossprod(x) -
#> crossprod(y))))
#> }
#> }, kpar = list(sigma = 0.1))
#> <bytecode: 0x555841d3c380>
#> <environment: 0x555841d3e850>
#> attr(,"kpar")
#> attr(,"kpar")$sigma
#> [1] 0.1
#>
#> attr(,"class")
#> [1] "rbfkernel"
#> attr(,"class")attr(,"package")
#> [1] "kernlab"
#>
#> Slot "kpar":
#> list()
#>
#> Slot "xmatrix":
#> [,1] [,2] [,3] [,4]
#> [1,] -0.62645381 0.398105880 -0.62036668 0.45018710
#> [2,] 0.18364332 -0.612026393 0.04211587 -0.01855983
#> [3,] -0.83562861 0.341119691 -0.91092165 -0.31806837
#> [4,] 1.59528080 -1.129363096 0.15802877 -0.92936215
#> [5,] 0.32950777 1.433023702 -0.65458464 -1.48746031
#> [6,] -0.82046838 1.980399899 1.76728727 -1.07519230
#> [7,] 0.48742905 -0.367221476 0.71670748 1.00002880
#> [8,] 0.73832471 -1.044134626 0.91017423 -0.62126669
#> [9,] 0.57578135 0.569719627 0.38418536 -1.38442685
#> [10,] -0.30538839 -0.135054604 1.68217608 1.86929062
#> [11,] 1.51178117 2.401617761 -0.63573645 0.42510038
#> [12,] 0.38984324 -0.039240003 -0.46164473 -0.23864710
#> [13,] -0.62124058 0.689739362 1.43228224 1.05848305
#> [14,] -2.21469989 0.028002159 -0.65069635 0.88642265
#> [15,] 1.12493092 -0.743273209 -0.20738074 -0.61924305
#> [16,] -0.04493361 0.188792300 -0.39280793 2.20610246
#> [17,] -0.01619026 -1.804958629 -0.31999287 -0.25502703
#> [18,] 0.94383621 1.465554862 -0.27911330 -1.42449465
#> [19,] 0.82122120 0.153253338 0.49418833 -0.14439960
#> [20,] 0.59390132 2.172611670 -0.17733048 0.20753834
#> [21,] 0.91897737 0.475509529 -0.50595746 2.30797840
#> [22,] 0.78213630 -0.709946431 1.34303883 0.10580237
#> [23,] 0.07456498 0.610726353 -0.21457941 0.45699881
#> [24,] -1.98935170 -0.934097632 -0.17955653 -0.07715294
#> [25,] 0.61982575 -1.253633400 -0.10019074 -0.33400084
#> [26,] -0.05612874 0.291446236 0.71266631 -0.03472603
#> [27,] -0.15579551 -0.443291873 -0.07356440 0.78763961
#> [28,] -1.47075238 0.001105352 -0.03763417 2.07524501
#> [29,] -0.47815006 0.074341324 -0.68166048 1.02739244
#> [30,] 0.41794156 -0.589520946 -0.32427027 1.20790840
#> [31,] 1.35867955 -0.568668733 0.06016044 -1.23132342
#> [32,] -0.10278773 -0.135178615 -0.58889449 0.98389557
#> [33,] 0.38767161 1.178086997 0.53149619 0.21992480
#> [34,] -0.05380504 -1.523566800 -1.51839408 -1.46725003
#> [35,] -1.37705956 0.593946188 0.30655786 0.52102274
#> [36,] -0.41499456 0.332950371 -1.53644982 -0.15875460
#> [37,] -0.39428995 1.063099837 -0.30097613 1.46458731
#> [38,] -0.05931340 -0.304183924 -0.52827990 -0.76608200
#> [39,] 1.10002537 0.370018810 -0.65209478 -0.43021175
#> [40,] 0.76317575 0.267098791 -0.05689678 -0.92610950
#> [41,] -0.16452360 -0.542520031 -1.91435943 -0.17710396
#> [42,] -0.25336168 1.207867806 1.17658331 0.40201178
#> [43,] 0.69696338 1.160402616 -1.66497244 -0.73174817
#> [44,] 0.55666320 0.700213650 -0.46353040 0.83037317
#> [45,] -0.68875569 1.586833455 -1.11592011 -1.20808279
#> [46,] -0.70749516 0.558486426 -0.75081900 -1.04798441
#> [47,] 0.36458196 -1.276592208 2.08716655 1.44115771
#> [48,] 0.76853292 -0.573265414 0.01739562 -1.01584747
#> [49,] -0.11234621 -1.224612615 -1.28630053 0.41197471
#> [50,] 0.88110773 -0.473400636 -1.64060553 -0.38107605
#>
#> Slot "kcall":
#> .local(x = x, kernel = "rbfdot", features = 2)
#>
#> Slot "terms":
#> NULL
#>
#> Slot "n.action":
#> NULL
#>
#>
# }
