def train(self): """ TODO: Question 1 - Binary Perceptron Train the perceptron until convergence. To iterate through all of the data points once (a single epoch), you can do: for x, y in self.get_data_and_monitor(self): ... get_data_and_monitor yields data points one at a time. It also takes the perceptron as an argument so that it can monitor performance and display graphics in between yielding data points. """ # "*** YOUR CODE HERE ***" train_over = False cnt = 0 while not train_over: train_over = True cnt = 0 for x, y in self.get_data_and_monitor(self): if self.update(x, y): cnt += 1 train_over = False if not train_over: self.get_data_and_monitor = backend.make_get_data_and_monitor_perceptron( )
def __init__(self, dimensions): """ Initialize a new Perceptron instance. A perceptron classifies data points as either belonging to a particular class (+1) or not (-1). `dimensions` is the dimensionality of the data. For example, dimensions=2 would mean that the perceptron must classify 2D points. """ self.get_data_and_monitor = backend.make_get_data_and_monitor_perceptron() self.weights = np.zeros(dimensions)
def __init__(self, dimensions): """ Initialize a new Perceptron instance. A perceptron classifies data points as either belonging to a particular class (+1) or not (-1). `dimensions` is the dimensionality of the data. For example, dimensions=2 would mean that the perceptron must classify 2D points. """ self.get_data_and_monitor = backend.make_get_data_and_monitor_perceptron( ) #create and store a weight vector represented as a numpy array of zeros #get_weight will return this vector self.vec = np.zeros( dimensions) #creating a vector with the given dimension # self.storage = [] # creating an empty array for storing vectors # self.storage.append(self.vec) "*** YOUR CODE HERE ***"