mercredi 9 décembre 2020

dimensionally reduction python

I have wrote the MNIST digits data that look like:

digits = datasets.load_digits(n_class=6)
X = digits.data
y = digits.target

n_samples, n_features = X.shape
n_neighbors = 30


# visualizing input data
a = 20
img = np.zeros((10 * a, 10 * a))
for i in range(a):
    ix = 10 * i + 1
    for j in range(a):
        iy = 10 * j + 1
        img[ix:ix + 8, iy:iy + 8] = X[i * a + j].reshape((8, 8))

plt.figure(figsize=(5,5))
plt.imshow(img, cmap=plt.cm.binary);
plt.xticks([]);
plt.yticks([]);

# compute time
ctime = np.zeros(8)

# set file name
f_file = 'ctime.csv'

And this is PCA algorithm:

t0 = time()

clf = decomposition.TruncatedSVD(n_components=2)

Y = clf.fit_transform(X-X.mean(axis=0))

plot_embedding(Y)

dt = time() - t0

print("Compute time = %.2f sec" % dt)

ctime[0] = dt

What I want to do now is to vary the number of input data points for each fitting and take a random sample of data points from the original data. I would like to do this for 21 sample sizes that are equividistant in a logarithimic scale (base 10) between the end points 100 to 1000 (1083 is the total number of points in the MNIST dataset) up to rounding to integers.

I guess I have to use sample_without_replacement() function from sklearn to randomly select sample for each time I run the PCA algorithm, but I have no idea how to approach the original data. Any advise or hint would be really helpful.

I have been trying to write the code for couple of days but it does not work.




Aucun commentaire:

Enregistrer un commentaire