def raw_predict(self, X): check_is_fitted(self, ['X_', 'y_']) X = check_array(X) y = np.dot(X, self.w_) for idxi in xrange(y.size): y[idxi] = sigmoid(y[idxi]) return y
def predict(self, X): check_is_fitted(self, ['X_', 'y_']) X = check_array(X) n_samples = X.shape[0] y_test_predict = np.zeros(n_samples) for t in xrange(n_samples): wtx = np.dot(X[t, :], self.w_) p = sigmoid(wtx) y_test_predict[t] = 0. if p < 0.5 else 1. return y_test_predict
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)
def raw_predict(self, X): check_is_fitted(self, ['X_', 'y_']) X = check_array(X) n_samples = X.shape[0] y_test_predict = np.zeros(n_samples) g_sum = np.zeros(self.n_factors) g_sum_sqr = np.zeros(self.n_factors) for t in range(n_samples): y_test_predict[t] = sigmoid(self._predict_with_feedback(X[t, :], g_sum, g_sum_sqr)) return y_test_predict
def raw_predict(self, X): check_is_fitted(self, ['X_', 'y_']) X = check_array(X) n_samples, n_features = X.shape w = np.zeros(n_features) for idxi in range(n_features): w[idxi] = self._get_w(idxi) y = np.dot(X, w) for idxi in range(y.size): y[idxi] = sigmoid(y[idxi]) return y
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)
def predict(self, X): check_is_fitted(self, ['X_', 'y_']) X = check_array(X) n_samples, n_features = X.shape y_test_predict = np.zeros(n_samples) w = np.zeros(n_features) for idxi in range(n_features): w[idxi] = self._get_w(idxi) # print w for t in range(n_samples): x = X[t, :] wtx = np.dot(w, x) p = sigmoid(wtx) y_test_predict[t] = 0. if p < 0.5 else 1. return y_test_predict