I am using input data from here (see Section 3.1).
I am trying to reproduce their covariance matrix, eigenvalues, and eigenvectors using scikit-learn. However, I am unable to reproduce the results as presented in the data source. I've also seen this input data elsewhere but I can't discern whether it's a problem with scikit-learn, my steps, or the data source.
data = np.array([[2.5,2.4],
[0.5,0.7],
[2.2,2.9],
[1.9,2.2],
[3.1,3.0],
[2.3,2.7],
[2.0,1.6],
[1.0,1.1],
[1.5,1.6],
[1.1,0.9],
])
centered_data = data-data.mean(axis=0)
pca = PCA()
pca.fit(centered_data)
print(pca.get_covariance()) #Covariance Matrix
array([[ 0.5549, 0.5539],
[ 0.5539, 0.6449]])
print(pca.explained_variance_ratio_) #Eigenvalues (normalized)
[ 0.96318131 0.03681869]
print(pca.components_) #Eigenvectors
[[-0.6778734 -0.73517866]
[ 0.73517866 -0.6778734 ]]
Surprisingly, the projections matches the results from the data source described above.
print(pca.transform(centered_data)) #Projections
array([[-0.82797019, 0.17511531],
[ 1.77758033, -0.14285723],
[-0.99219749, -0.38437499],
[-0.27421042, -0.13041721],
[-1.67580142, 0.20949846],
[-0.9129491 , -0.17528244],
[ 0.09910944, 0.3498247 ],
[ 1.14457216, -0.04641726],
[ 0.43804614, -0.01776463],
[ 1.22382056, 0.16267529]])
Here is what I don't understand:
- Why is the covariance matrix is different?
- Updated: How do I get eigenvalues from scikit-learn that are not already normalized?