Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Binary classification with a Perceptron

image.png

Step 0 - Get the Iris dataset

Loading...
<Figure size 960x720 with 1 Axes>

We’re going to focus on binary classification, so let’s pick two of these classes to distinguish.

Fitting a dataset with X: (100, 2) and y: (100,)
There are 50 examples of Iris-versicolor
<Figure size 960x720 with 1 Axes>

Step 1 - Define and fit Perceptron class

We’re going to follow the sklearn-ish protocol of having a fit and predict function. There are advantages and disadvantages to this for deep learning but we won’t get into that right now.

<__main__.Perceptron at 0x7f365c1e24d0>
<Figure size 960x720 with 1 Axes>

Step 2 - Plot decision boundary

<Figure size 960x720 with 1 Axes>

If I am ultra careful about scaling units correctly, I can see that the weight vector of the model is perpendicular to the decision boundary!

<Figure size 960x720 with 1 Axes>

We can look at what the decision boundary was before fitting too!

It’s not very interesting

<Figure size 960x720 with 1 Axes>