Implementing a perceptron learning algorithm in Python
In the previous section, we learned how Rosenblatt’s perceptron rule works; let’s now implement it in Python and apply it to the Iris dataset that we introduced in Chapter 1, Giving Computers the Ability to Learn from Data.
An object-oriented perceptron API
We will take an object-oriented approach to defining the perceptron interface as a Python class, which will allow us to initialize new Perceptron
objects that can learn from data via a fit
method and make predictions via a separate predict
method. As a convention, we append an underscore (_
) to attributes that are not created upon the initialization of the object, but we do this by calling the object’s other methods, for example, self.w_
.
Additional resources for Python’s scientific computing stack
If you are not yet familiar with Python’s scientific libraries or need a refresher, please see the following resources...