This shows you the differences between two versions of the page.
code:cross_validation [2016/09/20 14:17] asa created |
code:cross_validation [2016/09/22 18:44] (current) asa |
||
---|---|---|---|
Line 40: | Line 40: | ||
converged = True | converged = True | ||
for i in range(len(X)) : | for i in range(len(X)) : | ||
- | if y[i] * self.discriminant(X[i]) <= 0 : | + | if y[i] * self.decision_function(X[i]) <= 0 : |
self.w = self.w + y[i] * self.learning_rate * X[i] | self.w = self.w + y[i] * self.learning_rate * X[i] | ||
converged = False | converged = False | ||
Line 48: | Line 48: | ||
print ('converged in %d iterations ' % iterations) | print ('converged in %d iterations ' % iterations) | ||
- | def discriminant(self, x) : | + | def decision_function(self, X) : |
- | return np.inner(self.w, x) | + | return np.inner(self.w, X) |
def predict(self, X) : | def predict(self, X) : | ||
Line 63: | Line 63: | ||
scores = np.inner(self.w, X) | scores = np.inner(self.w, X) | ||
return np.sign(scores) | return np.sign(scores) | ||
+ | |||
+ | |||
+ | if __name__=='__main__' : | ||
+ | X,y,w = generate_separable_data(40) | ||
+ | p = Perceptron() | ||
+ | p.fit(X,y) | ||
</file> | </file> |