code:perceptron

# Differences

This shows you the differences between two versions of the page.

 code:perceptron [2016/08/09 16:25]127.0.0.1 external edit code:perceptron [2016/09/08 17:04] (current)asa Both sides previous revision Previous revision 2016/09/08 17:04 asa 2016/08/09 16:25 external edit2015/09/03 21:03 asa 2015/08/28 16:36 asa 2015/08/28 16:35 asa 2013/09/06 15:55 asa 2013/08/15 16:42 asa created 2016/09/08 17:04 asa 2016/08/09 16:25 external edit2015/09/03 21:03 asa 2015/08/28 16:36 asa 2015/08/28 16:35 asa 2013/09/06 15:55 asa 2013/08/15 16:42 asa created Line 47: Line 47: self.converged = converged self.converged = converged if converged : if converged : - print '​converged in %d iterations ' % iterations + print ('​converged in %d iterations ' % iterations) def discriminant(self,​ x) : def discriminant(self,​ x) : - return np.dot(self.w, x) + return np.inner(self.w, x) ​ ​ def predict(self,​ X) : def predict(self,​ X) : Line 63: Line 63: """​ """​ ​ ​ - scores = np.dot(self.w, X) + scores = np.inner(self.w, X) return np.sign(scores) return np.sign(scores) def generate_separable_data(N) : def generate_separable_data(N) : - xA,yA,xB,yB = [np.random.uniform(-1,​ 1) for i in range(4)] w = np.random.uniform(-1,​ 1, 2) w = np.random.uniform(-1,​ 1, 2) - print w,w.shape + print (w,w.shape) X = np.random.uniform(-1,​ 1, [N, 2]) X = np.random.uniform(-1,​ 1, [N, 2]) - print X,X.shape + print (X,X.shape) y = np.sign(np.dot(X,​ w)) y = np.sign(np.dot(X,​ w)) return X,y,w return X,y,w Line 91: Line 90: p = Perceptron() p = Perceptron() p.fit(X,y) p.fit(X,y) -