Implementing a perceptron learning algorithm in Python
In the previous section, we learned how the Rosenblatt's perceptron rule works; let us now go ahead and 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 define the perceptron interface as a Python class, which allows 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 being created upon the initialization of the object but by calling the object's other methods, for example, self.w_
.
Note
If you are not yet familiar with Python's scientific libraries or need a refresher, please see the following resources: