def _train(self, X, y, n_samples, _):
        iter_idx = np.arange(n_samples)
        np.random.shuffle(iter_idx)
        for t, data_idx in enumerate(iter_idx):
            curr_x = X[data_idx, :]
            curr_y = y[data_idx]

            wtx = np.dot(curr_x, self.w_)

            curr_p = sigmoid(wtx)
            log_likelihood = logloss(curr_p, curr_y)

            self.train_tracker_.track(log_likelihood)
            self._update(curr_y, curr_p, curr_x)
Ejemplo n.º 2
0
    def _train(self, X, y, n_samples, n_features):
        iter_idx = np.arange(n_samples)
        np.random.shuffle(iter_idx)
        for t, data_idx in enumerate(iter_idx):
            curr_x = X[data_idx, :]
            curr_y = y[data_idx]

            wtx = 0.
            curr_w = {}
            for idxi in range(n_features):
                curr_w[idxi] = self._get_w(idxi)
                wtx += (curr_w[idxi] * curr_x[idxi])

            curr_p = sigmoid(wtx)
            log_likelihood = logloss(curr_p, curr_y)

            self.train_tracker_.track(log_likelihood)
            self._update(curr_y, curr_p, curr_x, curr_w)
Ejemplo n.º 3
0
    def _train(self, X, y, n_samples, _):
        iter_idx = np.arange(n_samples)
        np.random.shuffle(iter_idx)

        g_sum = np.zeros(self.n_factors)
        g_sum_sqr = np.zeros(self.n_factors)
        for t, data_idx in enumerate(iter_idx):
            curr_x = X[data_idx, :]
            curr_y = y[data_idx]
            curr_y_adj = -1. if curr_y == 0. else 1.

            p = self._predict_with_feedback(curr_x, g_sum, g_sum_sqr)

            # TODO: multiplier can go out of control if the learning rate is too big, why?
            multiplier = -curr_y_adj * (1. - 1./(1. + exp(-curr_y_adj*p))) * self.class_weight_[curr_y]
            log_likelihood = logloss(p, curr_y)

            self.train_tracker_.track(log_likelihood)
            self._update(curr_x, g_sum, multiplier)