Build a Simple Classifier

Learn how to build a linear classifier with the help of training data examples.

We'll cover the following

Linear classifier

We want to train our linear classifier to correctly classify bugs as ladybugs or caterpillars. As we saw before, this is simply about refining the slope of the dividing line that separates the two groups of points on a plot showing width and height.

Rather than developing a mathematical theory upfront, let’s try to get a feel for what we need to do by trying to do it. We’ll understand the mathematics better that way. We do need some examples to learn from. The following table shows two simple examples.

Example Width Length Bug
1 3.0 1.0 Ladybug
2 1.0 3.0 Caterpillar

We have one example of a bug that has a width of 3.03.0 and a length of 1.01.0, which we know is a ladybug. We also have an example of a bug that is 3.03.0 long and 1.01.0 wide, which is a caterpillar. This is a set of examples that we know to be the truth. It is these examples that will help refine the slope of the classifier function. Examples of truth, used to teach a predictor or a classifier, are called training data.

Let’s plot these two training data examples. Visualizing data is often very helpful to get a better understanding of it, which isn’t easy to get just by looking at a list or table of numbers.

Get hands-on with 1200+ tech skills courses.