Skip to content

Instantly share code, notes, and snippets.

@buriy
Created August 16, 2016 16:04
Show Gist options
  • Save buriy/0e006dbfb41b438533a3217541876d39 to your computer and use it in GitHub Desktop.
Save buriy/0e006dbfb41b438533a3217541876d39 to your computer and use it in GitHub Desktop.
When PCA transform doesn't help much
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