listing training perceptron by observation the learning rate of an algorithm is the adjustment it makes every time new observation comes in if this is highthe model will adjust quickly to new observations but might "overshootand never get precise an oversimplified examplethe optimal (and unknownweight for an -variable current estimation is with learning rate of the adjustment (learning rate (size of error (value of (current weight (adjustment (new weight)instead of the adjustment was too big to get the correct result the __init__ method of any python class is always run when creating an instance of the class several default values are set here sets up import numpy as np perceptron class class perceptron()def __init__(selfx,ythreshold learning_rate max_epochs )self threshold threshold self learning_rate learning_rate self self self max_epochs max_epochs the threshold is an arbitrary cutoff between and to decide whether the prediction becomes or often it' right in the middlebut it depends on the use case and variables are assigned to the class one epoch is one run through all the data we allow for maximum of runs until we stop the perceptron each observation will end up with weight the initialize function sets these weights for each incoming observation we allow for optionsall weights start at or they are assigned small (between and random weight def initialize(selfinit_type 'zeros')if init_type ='random'self weights np random rand(len(self [ ]) if init_type ='zeros'self weights np zeros(len(self [ ])we start at the first epoch the training function true is always trueso technically this is never-ending loopbut we build in several stop (breakconditions def train(self)epoch while trueadds one to the current error_count number of epochs epoch + for ( ,yin zip(self xself )error_count +self train_observation( , ,error_countinitiates the number of encountered errors at for each epoch this is importantif an epoch ends without errorsthe algorithm converged and we're done we loop through the data and feed it to the train observation functionone observation at time