handling large data on single computer if we reach the maximum number of allowed runswe stop looking for solution if error_count = print "training successfulbreak if epoch >self max_epochsprint "reached maximum epochsno perfect predictionbreak if by the end of the epoch we don' have an errorthe training was successful the real value (yis either or the prediction is also or if it' wrong we get an error of either or - the train observation function is run for every observation and will adjust the weights using the formula explained earlier def train_observation(self, ,yerror_count)result np dot(xself weightsself threshold error result in case we have wrong prediction (an error)we need to adjust the model we return the error count because we need to evaluate it at the end of the epoch the predict class our (targetdata vector adds to the error count prediction is made for this observation because it' binarythis will be either or for every predictor variable if error ! in the input vector ( )we'll error_count + adjust its weight for indexvalue in enumerate( )self weights[index+self learning_rate error value return error_count adjusts the weight for every predictor variable using the learning ratethe errorand the actual value of the predictor variable def predict(selfx)return int(np dot(xself weightsself thresholdthe values of the predictor values are multiplied by their respective weights (this multiplication is done by np dotthen the outcome is compared to the overall threshold (here this is to see if or should be predicted [( , , ),( , , ),( , , ),( , , ),( , , ),( , , ) [ , , , , , perceptron( ,yp initialize( train(print predict(( , , )print predict(( , , )we check what the perceptron would now predict given different values for the predictor variables in the first case it will predict in the second it predicts we instantiate our perceptron class with the data from matrix and vector our (predictorsdata matrix the weights for the predictors are initialized (as explained previouslythe perceptron model is trained it will try to train until it either converges (no more errorsor it runs out of training runs (epochs