Pattern Recognition in AI: Three Methods on One Digit Task

Pattern recognition on handwritten digits: 12.0, 5.0, and 0.95 percent test error for three methods, plus the nearest-neighbor bound and benchmark limits.

Last verified: October 20265 min read

Pattern recognition is the task of assigning an input, such as an image of a handwritten digit, to a category by learning regularities from labeled examples. On the MNIST digit benchmark, a 1998 paper in the Proceedings of the IEEE reported test error rates of 12.0 percent for a linear classifier, 5.0 percent for a nearest-neighbor method, and 0.95 percent for the convolutional network LeNet-5, which makes the data set a compact way to see how method choice changes results.

Key takeaways

  • MNIST holds 60,000 training images and 10,000 test images of handwritten digits, each 28 by 28 pixels, drawn from two National Institute of Standards and Technology (NIST) collections.
  • The same task, three methods: linear classifier 12.0 percent error, nearest neighbor 5.0 percent, LeNet-5 0.95 percent.
  • A nearest-neighbor rule has a proven limit: with enough data its error is at most twice the best possible error (the Bayes error), according to Cover and Hart in 1967.
  • A low score on one benchmark says little about handwriting from other writers, scanners, or alphabets.

What the task looks like in MNIST

MNIST was built from two NIST collections, Special Database 3 and Special Database 1. The first was collected from Census Bureau employees and the second from high school students, and the first is easier to read. Because a training set made of only one group would not predict performance on the other, the creators mixed them: the training set has 30,000 patterns from each, and the 10,000 test images take 5,000 from each. The writers in the test set are different from those in the training set. Each image was size-normalized to fit a 20 by 20 pixel box and centered in a 28 by 28 field, which adds gray levels from anti-aliasing. The labels are the digits zero through nine.

A pattern recognition system receives 784 numbers, one per pixel, and returns one of ten labels. Nothing in the data states what a seven looks like. The method has to find that regularity from the examples, which is why the topic sits between statistics and machine learning in textbooks such as Christopher Bishop's Pattern Recognition and Machine Learning (Springer, 2006).

Three methods on the same ten digits

The 1998 paper by Yann LeCun, Leon Bottou, Yoshua Bengio, and Patrick Haffner compares recognition methods on this digit task. A linear classifier draws straight boundaries in pixel space and reached 12.0 percent test error. A nearest-neighbor classifier with Euclidean distance labels a new image like its closest stored image and reached 5.0 percent. LeNet-5, a convolutional network that learns small filters shared across the image, reached 0.95 percent. The paper concludes that convolutional networks outperform other techniques on this benchmark, because they are designed for the variability of two-dimensional shapes.

The ordering matters more than the exact numbers. Each step uses more of the image's structure: no structure, then similarity between whole images, then local shapes that repeat across positions.

Nearest neighbor: a rule simple enough to check by hand

The nearest-neighbor rule needs no training. It stores every labeled example and assigns a new input the label of the closest one. In a 1967 paper in IEEE Transactions on Information Theory, Thomas Cover and Peter Hart showed that, for large samples, the error of this rule is bounded above by twice the Bayes probability of error. The result gives a worst-case guarantee for a rule that can be run on paper.

The table below is an illustrative example with invented numbers, not MNIST data. Two measurements describe each stored image of a handwritten one or seven: the ratio of height to width, and the fraction of the box covered by ink. A new image has ratio 2.1 and ink 0.30.

Stored imageHeight to widthInk fractionLabelDistance to new image
A2.40.28one0.30
B1.20.38seven0.90
C2.00.33one0.10
D1.50.45seven0.62

Image C is closest, so the rule labels the new image a one. Changing the scale of one measurement changes the distances, which shows why feature choice matters as much as the rule.

Why a benchmark score does not travel

MNIST digits are centered, size-normalized, and written by a small set of writers from two sources. A score of 0.95 percent applies to images prepared that way. Handwriting on forms, photographs of house numbers, or scripts with more than ten classes are different problems, and they need their own test sets. A model can also fit the quirks of a benchmark if it is tuned on the test images, so a course exercise should hold the test set aside until the end and report the error once.

FAQ

What is the difference between pattern recognition and machine learning?

The two overlap heavily. Pattern recognition names the task of assigning inputs to categories or values, and machine learning names the family of methods that learn the mapping from data. Bishop's textbook treats them together in one volume.

How big is the MNIST data set?

The training set has 60,000 images and the distributed test set has 10,000, each 28 by 28 pixels. The creators also built a larger test set of 60,000 samples, but only 10,000 are distributed.

Does 0.95 percent error mean the system reads any handwriting?

No. It means that LeNet-5 mislabeled that share of the benchmark's test digits, whose writers and preparation are described on the Idiap MNIST page. Other writers, devices, and scripts need separate testing.

Why do courses still use a data set from the 1990s?

It is small and well documented, with published results for many methods, so a student can compare a new method against known numbers. Its age and simplicity are also its limits.

Last verified: October 2026

Sources

  • Gradient-based learning applied to document recognition, LeCun Y, Bottou L, Bengio Y, Haffner P, Proceedings of the IEEE, November 1998
  • The MNIST Database of Handwritten Digits, as described by Idiap Research Institute, BEAT platform
  • Nearest neighbor pattern classification, Cover T M, Hart P E, IEEE Transactions on Information Theory 13(1), 1967
  • Pattern Recognition and Machine Learning, Bishop C M, Springer, 2006

New to artificial intelligence?

Start with the basics, then follow the guides to tools, rules, and effects on society.

Start with AI Basics