Our Own MNIST Library

Let’s recap where we are and where we want to go. In the previous chapters, we built a binary classifier. Now we want to apply that program to MNIST.

As a first step, we need to reshape MNIST’s images and labels into an input for our program. Let’s see how to do that.

Preparing the Input Matrices

Our binary classifier program expects its input formatted as two matrices: a set of examples X, and a set of labels Y. Let’s start with the matrix of examples X.

X is supposed to have one line per example and one column per input variable, plus a bias column full of 1s. (Remember the bias column? We talked about it in Bye Bye, Bias.)

To fit MNIST’s images to this format, we can reshape each image to a single line of pixels, ...

Get Programming Machine Learning 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.