09.05.2023 Views

pdfcoffee

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Unsupervised Learning

A comparison of the original and reduced data shape is done in the following code:

print('original data shape',x_train.shape)

print('reduced data shape', pca.shape)

----------------------------------------------------

original data shape (60000, 784)

reduced data shape (60000, 3)

Finally let us plot the data points in the three-dimensional space.

Set = sns.color_palette("Set2", 10)

color_mapping = {key:value for (key,value) in enumerate(Set)}

colors = list(map(lambda x: color_mapping[x], y_train))

fig = plt.figure()

ax = Axes3D(fig)

ax.scatter(pca[:, 0], pca[:, 1],pca[:, 2], c=colors)

You can see that the points corresponding to the same color and hence same label

are clustered together. We have therefore successfully used PCA to reduce the

dimensions of MNIST images. Each original image was of size 28 × 28. Using

the PCA method we can reduce it to a smaller size. Normally for image data,

dimensionality reduction is necessary. This is because images are large in size

and contain a significant amount of redundant data.

[ 378 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!