pca

Principal component analysis of raw data.

pca
(
Flag!"allowDestroy" allowDestroy = No.allowDestroy
Iterator
SliceKind kind
)
(
Slice!(Iterator, 2, kind) matrix
,
in Flag!"centerColumns" cc = Yes.centerColumns
)

Parameters

matrix Slice!(Iterator, 2, kind)

input M x N matrix, where 'M (rows)>= N(cols)'

cc Flag!"centerColumns"

Flag to centern columns. True by default.

Return Value

Type: auto

Examples

import mir.ndslice;

import mir.math.common: approxEqual;
import mir.algorithm.iteration: equal;

auto ingedients = [
     7,  26,   6,  60,
     1,  29,  15,  52,
    11,  56,   8,  20,
    11,  31,   8,  47,
     7,  52,   6,  33,
    11,  55,   9,  22,
     3,  71,  17,   6,
     1,  31,  22,  44,
     2,  54,  18,  22,
    21,  47,   4,  26,
     1,  40,  23,  34,
    11,  66,   9,  12,
    10,  68,   8,  12].sliced(13, 4);

auto res = ingedients.pca;

auto coeff = [
    -0.067799985695474,  -0.646018286568728,   0.567314540990512,   0.506179559977705,
    -0.678516235418647,  -0.019993340484099,  -0.543969276583817,   0.493268092159297,
     0.029020832106229,   0.755309622491133,   0.403553469172668,   0.515567418476836,
     0.730873909451461,  -0.108480477171676,  -0.468397518388289,   0.484416225289198,
].sliced(4, 4);

auto score = [
     36.821825999449700,  -6.870878154227367,  -4.590944457629745,   0.396652582713912,
     29.607273420710964,   4.610881963526308,  -2.247578163663940,  -0.395843536696492,
    -12.981775719737618,  -4.204913183175938,   0.902243082694698,  -1.126100587210615,
     23.714725720918022,  -6.634052554708721,   1.854742000806314,  -0.378564808384691,
     -0.553191676624597,  -4.461732123178686,  -6.087412652325177,   0.142384896047281,
    -10.812490833309816,  -3.646571174544059,   0.912970791674604,  -0.134968810314680,
    -32.588166608817929,   8.979846284936063,  -1.606265913996588,   0.081763927599947,
     22.606395499005586,  10.725906457369449,   3.236537714483416,   0.324334774646368,
     -9.262587237675838,   8.985373347478788,  -0.016909578102172,  -0.543746175981799,
     -3.283969329640680, -14.157277337500918,   7.046512994833761,   0.340509860960606,
      9.220031117829379,  12.386080787220454,   3.428342878284624,   0.435152769664895,
    -25.584908517429557,  -2.781693148152386,  -0.386716066864491,   0.446817950545605,
    -26.903161834677597,  -2.930971165042989,  -2.445522630195304,   0.411607156409658,
].sliced(13, 4);

auto latent = [5.177968780739053, 0.674964360487231, 0.124054300480810, 0.002371532651878].sliced;
latent[] *= 100;

assert(equal!approxEqual(res.coeff, coeff));
assert(equal!approxEqual(res.score, score));
assert(equal!approxEqual(res.latent, latent));

Meta