July 2017
Intermediate to advanced
382 pages
9h 13m
English
Perceptrons are easy enough to be implemented from scratch. We can mimic the typical OpenCV or scikit-learn implementation of a classifier by creating a Perceptron object. This 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.
When we initialize a new perceptron object, we want to pass a learning rate (lr, or η in the previous section) and the number of iterations after which the algorithm should terminate (n_iter):
In [1]: import numpy as npIn [2]: class Perceptron(object):... def __init__(self, lr=0.01, n_iter=10):... self.lr = lr... self.n_iter = n_iter...
The fit method is where most of the work is done. ...
Read now
Unlock full access