O'Reilly logo

Computer Vision with Python 3 by Saurabh Kapur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

MNIST digit classification using neural networks

To understand all these concepts better, let's implement our own neural network using the sklearn library. We will use the MNIST digits dataset for our task. The steps involved in training our network are:

  1. Preprocess the dataset by normalizing the pixel values of the images between 0, 1 or -1, and 1 (to make the mean 0).
  2. Prepare the dataset. Split the dataset into two sets—training set and testing set.
  3. Start training the dataset over the test data.
  4. Compute your network's performance over the test dataset.

The following code trains a neural network for classification of handwritten digits (MNIST dataset):

from sklearn.datasets import fetch_mldatafrom sklearn.neural_network import MLPClassifier ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required