chapter five

5 Using lines to split our points: The perceptron algorithm

 

In this chapter

  • what is classification?
  • sentiment analysis: how to tell if a sentence is happy or sad using machine learning
  • drawing a line that separates points of two colors
  • what is a perceptron, and how do we train it?
  • coding the perceptron algorithm in Python and scikit-learn

In this chapter, we learn a branch of machine learning called classification. Classification models are similar to regression models, in that their aim is to predict the labels of a dataset based on the features. The difference is that regression models aim to predict a number, whereas classification models aim to predict a state or a category. Classification models are often called classifiers, and we’ll use the terms interchangeably. Many classifiers predict one of two possible states (often yes/no), although it is possible to build classifiers that predict among a higher number of possible states. The following are popular examples of classifiers:

  • A recommendation model that predicts whether a user will watch a certain movie
  • An email model that predicts whether an email is spam or ham
  • A medical model that predicts whether a patient is sick or healthy
  • An image-recognition model that predicts whether an image contains an automobile, a bird, a cat, or a dog
  • A voice recognition model that predicts whether the user said a particular command

The problem: We are on an alien planet, and we don’t know their language!

A slightly more complicated planet

Does our classifier need to be correct all the time? No

A more general classifier and a slightly different way to define lines

The step function and activation functions: A condensed way to get predictions

What happens if I have more than two words? General definition of the perceptron classifier

The bias, the y-intercept, and the inherent mood of a quiet alien

How do we determine whether a classifier is good or bad? The error function

How to compare classifiers? The error function

How to find a good classifier? The perceptron algorithm

The perceptron trick: A way to slightly improve the perceptron

Repeating the perceptron trick many times: The perceptron algorithm

Gradient descent

Stochastic and batch gradient descent

Coding the perceptron algorithm

Coding the perceptron trick

Coding the perceptron algorithm

Coding the perceptron algorithm using scikit-learn

Applications of the perceptron algorithm

Spam email filters

Recommendation Systems

Health care

Computer vision

Summary

Exercises