Skip to content

2 PCA implementations that give same results but different from Python scikit-learn implementation ... #81

@SergeStinckwich

Description

@SergeStinckwich

We have 2 implementations of PCA :

  • one based on Jacobi Transformation of the covariance matrix
  • another one based on SVD.

They give the same results but the result are different from the one you can find with sci-kit learn in Python:

import numpy as np
from sklearn.decomposition import PCA
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
pca = PCA(n_components=2)
pca.fit(X)
pca.components_
pca.transform(X)

pca.components_ returns :

array([[-0.83849224, -0.54491354],
       [ 0.54491354, -0.83849224]])

pca.transform(X) returns:

array([[ 1.38340578,  0.2935787 ],
       [ 2.22189802, -0.25133484],
       [ 3.6053038 ,  0.04224385],
       [-1.38340578, -0.2935787 ],
       [-2.22189802,  0.25133484],
       [-3.6053038 , -0.04224385]])

I try to implement a flipsvd method like this one : https://github.com/scikit-learn/scikit-learn/blob/4c65d8e615c9331d37cbb6225c5b67c445a5c959/sklearn/utils/extmath.py#L609
but fails until now.

Please have a look to tests of PMPrincipalComponentAnalyserTest.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions