Chapter 5
A Discerning Machine

We started our journey in machine learning by way of linear regression. Now we’re going to use that knowledge (and that code) to branch off toward our goal: a program that recognizes images.

This chapter covers the first step toward image recognition. We’ll build a classifier—a program that assigns data to one of a limited number of classes. Instead of numerical labels, classifiers work with categorical labels. As an example, consider the difference betwen our pizza predictor and a system that recognizes plants. The pizza predictor outputs a number. By contrast, the plant classifier would output the name of a plant, taken from a predefined list of possible species.

In this chapter, we’ll start off small: our classifier will be a binary classifier that only recognizes two classes. Many useful real-life systems are based on binary classification. For example, the pneumonia detector that we described in the first chapter assigns X-ray scans to either the class “pneumonia” or the class “no pneumonia.”

In the next few pages, we’ll replace the linear regression in our program with binary classification. We’ll start with a classification problem that has nothing to do with computer vision—however, in the next chapter we’ll turn around and apply that binary classifier to an image recognition problem.

Before we dive in, be aware of a slight change in vocabulary. So far, I said that a learning system works in two phases: training and prediction. From now on, I’ll call those two phases “training” and “classification” instead, to emphasize that the result of our prediction is a categorical label. “Classification” is just a specific type of prediction, so I’ll use the more specific term.