Created
April 20, 2019 16:25
-
-
Save hemalvarambhia/03e23c9d499d8b4d0b19849c90c53279 to your computer and use it in GitHub Desktop.
Using Scikit-Learn's PCA to reproduce the results of the Lindsay Smith PCA Tutorial Paper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from numpy.linalg import inv | |
from scipy import linalg | |
from sklearn.decomposition import PCA | |
from sklearn import utils | |
X = 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, 1.6], [1, 1.1], [1.5, 1.6], [1.1, 0.9]]) | |
mean_ = np.mean(X, axis=0) | |
X = X - mean_ | |
pca = PCA(n_components=2) | |
pca.fit(X) | |
pca.components_ | |
pca.transform(X) | |
print(X) | |
print('components = ', pca.components_) | |
print('================') | |
print(pca.transform(X)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment