def fit(self, train, target, alpha=0.0001, max_loop=130, converge=0.001):
     m, n = train.shape
     self.weights = np.zeros(n)
     for k in range(max_loop):
         prev_error = mse(self.predict(train), target)
         self.print_progress(k, prev_error)
         for t in xrange(m):
             data_point = train[t]
             predict = self.predict(data_point)
             error = predict - target[t]
             self.weights -= alpha * error * predict * (1.0 - predict) * data_point
         if abs(prev_error - mse(self.predict(train), target)) <= converge:
             break
     return self
Example #2
0
 def fit(self, train, target, alpha=0.0001, max_loop=130, converge=0.001):
     m, n = train.shape
     self.weights = np.zeros(n)
     for k in range(max_loop):
         prev_error = mse(self.predict(train), target)
         self.print_progress(k, prev_error)
         for t in range(m):
             data_point = train[t]
             error = self.predict(data_point) - target[t]
             self.weights -= alpha * error * data_point
             print self.weights
         if abs(prev_error - mse(self.predict(train), target)) <= converge:
             break
     return self
    def fit(self, train, target, alpha=0.0001, max_loop=1300, converge=0.0001, beta=10):
        m, n = train.shape
        self.weights = np.ones(n)
        for k in range(max_loop):
            prev_error = mse(self.predict(train), target)
            self.print_progress(k, prev_error)
            predict = self.predict(train)
            error = predict - target
            self.weights -= alpha * (train.T.dot(error) + beta * self.weights)

        return self
Example #4
0
    def fit(self,
            train,
            target,
            alpha=0.0001,
            max_loop=1300,
            converge=0.0001,
            beta=10):
        m, n = train.shape
        self.weights = np.ones(n)
        for k in range(max_loop):
            prev_error = mse(self.predict(train), target)
            self.print_progress(k, prev_error)
            predict = self.predict(train)
            error = predict - target
            self.weights -= alpha * (train.T.dot(error) + beta * self.weights)

        return self