Exemple #1
0
r = random.normal(2,0.1,50)
data[50:100,0] = r*cos(theta)
data[50:100,1] = r*sin(theta)

theta = random.normal(0,pi,50)
r = random.normal(5,0.1,50)
data[100:150,0] = r*cos(theta)
data[100:150,1] = r*sin(theta)

figure()
plot(data[:50,0],data[:50,1],'ok')
plot(data[50:100,0],data[50:100,1],'^k')
plot(data[100:150,0],data[100:150,1],'vk')
title('Original dataset')

x,y,evals,evecs = pca.pca(data,2)
figure()
plot(x[:50,0],x[:50,1],'ok')
plot(x[50:100,0],x[50:100,1],'^k')
plot(x[100:150,0],x[100:150,1],'vk')
title('Reconstructed points after PCA')

figure()
y = kernelpca.kernelpca(data,'gaussian',2)
plot(y[:50,0],y[:50,1],'ok')
plot(y[50:100,0],y[50:100,1],'^k')
plot(y[100:150,0],y[100:150,1],'vk')
title('Reconstructed points after kernel PCA')

show()
pl.plot(newData[w0,0],newData[w0,1],'ok')
pl.plot(newData[w1,0],newData[w1,1],'^k')
pl.plot(newData[w2,0],newData[w2,1],'vk')
pl.axis([-1.5,1.8,-1.5,1.8])
pl.axis('off')

import pca
x,y,evals,evecs = pca.pca(iris,2)
pl.figure(3)
pl.plot(y[w0,0],y[w0,1],'ok')
pl.plot(y[w1,0],y[w1,1],'^k')
pl.plot(y[w2,0],y[w2,1],'vk')
pl.axis('off')

import kernelpca
newData = kernelpca.kernelpca(iris,'gaussian',2)
pl.figure(4)
pl.plot(newData[w0,0],newData[w0,1],'ok')
pl.plot(newData[w1,0],newData[w1,1],'^k')
pl.plot(newData[w2,0],newData[w2,1],'vk')
pl.axis('off')

import factoranalysis
newData = factoranalysis.factoranalysis(iris,2)
#print newData
pl.figure(5)
pl.plot(newData[w0,0],newData[w0,1],'ok')
pl.plot(newData[w1,0],newData[w1,1],'^k')
pl.plot(newData[w2,0],newData[w2,1],'vk')
pl.axis('off')
Exemple #3
0
theta = np.random.normal(0, np.pi, 50)
r = np.random.normal(2, 0.1, 50)
data[50:100, 0] = r * np.cos(theta)
data[50:100, 1] = r * np.sin(theta)

theta = np.random.normal(0, np.pi, 50)
r = np.random.normal(5, 0.1, 50)
data[100:150, 0] = r * np.cos(theta)
data[100:150, 1] = r * np.sin(theta)

pl.figure()
pl.plot(data[:50, 0], data[:50, 1], 'ok')
pl.plot(data[50:100, 0], data[50:100, 1], '^k')
pl.plot(data[100:150, 0], data[100:150, 1], 'vk')
pl.title('Original dataset')

x, y, evals, evecs = pca.pca(data, 2)
pl.figure()
pl.plot(x[:50, 0], x[:50, 1], 'ok')
pl.plot(x[50:100, 0], x[50:100, 1], '^k')
pl.plot(x[100:150, 0], x[100:150, 1], 'vk')
pl.title('Reconstructed points after PCA')

pl.figure()
y = kernelpca.kernelpca(data, 'gaussian', 2)
pl.plot(y[:50, 0], y[:50, 1], 'ok')
pl.plot(y[50:100, 0], y[50:100, 1], '^k')
pl.plot(y[100:150, 0], y[100:150, 1], 'vk')
pl.title('Reconstructed points after kernel PCA')

pl.show()
Exemple #4
0
plot(data[w1, 0], data[w1, 1], "^k")
plot(data[w2, 0], data[w2, 1], "vk")
axis([-1.5, 1.8, -1.5, 1.8])
axis("off")
figure(2)
plot(newData[w0, 0], newData[w0, 1], "ok")
plot(newData[w1, 0], newData[w1, 1], "^k")
plot(newData[w2, 0], newData[w2, 1], "vk")
axis([-1.5, 1.8, -1.5, 1.8])
axis("off")

import pca

x, y, evals, evecs = pca.pca(data, 2)
figure(3)
plot(y[w0, 0], y[w0, 1], "ok")
plot(y[w1, 0], y[w1, 1], "^k")
plot(y[w2, 0], y[w2, 1], "vk")
axis("off")

import kernelpca

newData = kernelpca.kernelpca(data, "gaussian", 2)
figure(4)
plot(newData[w0, 0], newData[w0, 1], "ok")
plot(newData[w1, 0], newData[w1, 1], "^k")
plot(newData[w2, 0], newData[w2, 1], "vk")
axis("off")

show()