User Tools

Site Tools


code:perceptron

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
code:perceptron [2016/08/09 10:25]
127.0.0.1 external edit
code:perceptron [2016/09/08 11:04] (current)
asa
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)
- 
 </​file>​ </​file>​
code/perceptron.txt ยท Last modified: 2016/09/08 11:04 by asa