Extracting PCA components from MNIST

Before we move to our RBM, let's take a look at what happens when we apply a PCA to our dataset. Like we did in the last chapter, we will take our features (784 pixels that are either on or off) and apply an eigenvalue decomposition to the matrix to extract eigendigits from the dataset.

Let's take 100 components from the possible 784 and plot the components to see what the extracted features look like. We will do this by importing our PCA module, fitting it to our data with 100 components, and creating a matplotlib gallery to display the top 100 components available to us:

# import Principal Components Analysis module from sklearn.decomposition import PCA  # extract 100 "eigen-digits" pca = PCA(n_components=100) ...

Get Feature Engineering Made Easy now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.