#native_company# #native_desc#
#native_cta#

Improving MNIST

Let's get physical

Sometimes, nothing beats holding a copy of a book in your hands. Writing in the margins, highlighting sentences, folding corners. So this book is also available from Amazon as a paperback.

Buy now on Amazon

We’ve covered a few different methods of solving MNIST in this chapter. It’s a great solid introduction to Machine Learning, but it’s also just the beginning. You may have noticed that although the accuracy from the test data is relatively high, 90%+, the real-world accuracy from recognizing your hand-drawn digits is much lower.

In this lecture, I’ll discuss some methods you may want to employ to improve your model’s performance.

Note

They are just pointers; there is no code in our sample repository for you to look at. I’ll leave it as an exercise for you to explore and examine, in real life this is how you will work to improve the models you create, enjoy!

Input Normalization

The model was trained on a set of very normalized images; the shape and orientation of the handwritten digits are always the same. It’s written with a pen, whereas you will probably be trying to write with a mouse or track-pad, so your hand-drawn digits don’t quite look the same as the images in the data set.

One way you can try to improve the result is to make sure the input image is as close to the trained data as possible.

  1. Center the digit

    5.mnist.007
    Figure 1. Centering a digit
  2. Crop it to a square bounding box and then scaling up

    5.mnist.008
    Figure 2. Cropping a digit to a bounding box and then scaling
  3. Rotate the drawing, so the digit is always vertical

    5.mnist.009
    Figure 3. Rotating the digit so it is vertical

Data Augmentation

The solution above talks about how to change the input data to make it look as close as possible to the training data. On the flip side, we can turn the training data to make it more representative of the various ways people can write digits. This is called data augmentation.

Take your source data set, and for each image, create slightly different versions.

  1. You can try scaling the digits smaller and larger.

  2. You can try shifting them a few pixels left and right.

  3. You can try rotating them slightly clockwise and anticlockwise.

  4. You can try corrupting the images somewhat, delete pixels, add a pixel in other places.

  5. You can try to change the color or gray-scale values.

There are lots of ways you can adjust an image. Try to make the adjustments something that will be likely to happen in real life with the application rather than random, e.g. flipping by 90 degrees is perhaps unlikely with the application we are building here.

Create a new data set, much larger than the first with the images adjusted somehow, and run the model with the new data-set.

There are some helpful tools out there that can help create these adjusted images, imgaug[1] is one of them, but if you search for Data Augmentation Tools Machine Learning or something along those lines, you will find others.

Different Algorithms

There are many many different algorithms and collections of layers and methods you can use to solve MNIST.

Kaggle.com is an online platform where people compete to solve ML problems, like MNIST, to score the highest accuracy. There is a fantastic discussion[2] on Kaggle about the different algorithms you can use and the maximum accuracy that can be achieved for MNIST. I recommend you have a read of that it might give you some ideas for other things you can try.

Warning

Kaggle works on a system of honesty, there are ways to fake the results of your ML algorithm, and there are lots of fake results on the platform. If you look at the MNIST leader-board[3] on Kaggle, you’ll see a whole page of people who claim to have scored 100% accuracy, which is impossible. If you look at their code, all they are doing is passing through the test data as model outputs without any machine learning.


Advanced JavaScript

This unique course teaches you advanced JavaScript knowledge through a series of interview questions. Bring your JavaScript to the 2021's today.

Level up your JavaScript now!