Skip to content

Commit 365e9e9

Browse files
committed
compare pca svd
1 parent be04d8c commit 365e9e9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# https://deeplearningcourses.com/c/unsupervised-deep-learning-in-python
2+
# https://www.udemy.com/unsupervised-deep-learning-in-python
3+
from __future__ import print_function, division
4+
from builtins import range, input
5+
# Note: you may need to update your version of future
6+
# sudo pip install -U future
7+
8+
import numpy as np
9+
import matplotlib.pyplot as plt
10+
11+
from sklearn.decomposition import PCA, TruncatedSVD
12+
from util import getKaggleMNIST
13+
14+
15+
X, Y, _, _ = getKaggleMNIST()
16+
m = X.mean(axis=0)
17+
s = X.std(axis=0)
18+
np.place(s, s == 0, 1)
19+
X = (X - m) / s
20+
21+
pca = PCA()
22+
svd = TruncatedSVD()
23+
24+
Z1 = pca.fit_transform(X)
25+
Z2 = svd.fit_transform(X)
26+
27+
plt.subplot(1,2,1)
28+
plt.scatter(Z1[:,0], Z1[:,1], c=Y)
29+
plt.subplot(1,2,2)
30+
plt.scatter(Z2[:,0], Z2[:,1], c=Y)
31+
plt.show()

0 commit comments

Comments
 (0)