Created
August 16, 2016 16:04
-
-
Save buriy/0e006dbfb41b438533a3217541876d39 to your computer and use it in GitHub Desktop.
When PCA transform doesn't help much
This file contains 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 | |
import matplotlib.pyplot as plt | |
from sklearn.decomposition import PCA | |
def pca(data): | |
return PCA(n_components = 4).fit(data).transform(data) | |
a = numpy.zeros((100,12,12), dtype=numpy.float32) | |
for i in xrange(10): | |
for j in xrange(10): | |
a[i*10+j,i+1,j:j+3] = 1 | |
b = numpy.zeros((100,12,12), dtype=numpy.float32) | |
for i in xrange(10): | |
for j in xrange(10): | |
b[i*10+j,i:i+3,j+1] = 1 | |
vs=numpy.vstack([a,b]).reshape(200,12*12) | |
r=pca(vs) | |
plt.scatter(r[:100, 0], r[:100, 1], c = 'r') | |
plt.scatter(r[100:, 0], r[100:, 1], c = 'b') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment