def predict(self, X):
     assert self._is_trained, 'model must be trained before predict.'
     nSize = X.shape[0]
     param_list = unroll_parameter(self._parameter, self._parameter_shape)
     W, b = param_list[0], param_list[1]
     proj = np.dot(X, W) + np.repeat(np.reshape(b, (1, -1)), nSize, axis=0)
     h = sigmoid(proj)
     pred = [1 if v >= 0.5 else 0 for v in h]
     return np.array([self._ix2label[ix] for ix in pred])
 def predict(self, X):
     assert self._is_trained, 'model must be trained before predict.'
     nSize = X.shape[0]
     param_list = unroll_parameter(self._parameter, self._parameter_shape)
     W, b = param_list[0], param_list[1]
     proj = np.dot(X, W) + np.repeat(
         np.reshape(b, (1, b.shape[0])), X.shape[0], axis=0)
     h = sigmoid(proj)
     pred = [1 if v >= 0.5 else 0 for v in h]
     return np.array([self._ix2label[ix] for ix in pred])
 def feval(self, parameter, X, y):
     y = np.reshape(y, (y.shape[0], 1))
     param_list = unroll_parameter(parameter, self._parameter_shape)
     W, b = param_list[0], param_list[1]
     nSize = X.shape[0]
     h = np.dot(X, W) + np.repeat(np.reshape(b, (1, b.shape[0])), X.shape[0], axis=0)
     loss = self._lossor.calculate(y, h)
     residual = h - y
     grad_W = 1. / nSize * np.dot(X.T, residual)
     grad_b = 1. / nSize * np.sum(residual)
     grad_parameter = roll_parameter([grad_W, grad_b])
     return loss, grad_parameter
 def feval(self, parameter, X, y):
     y = np.reshape(y, (y.shape[0], 1))
     param_list = unroll_parameter(parameter, self._parameter_shape)
     W, b = param_list[0], param_list[1]
     nSize = X.shape[0]
     proj = np.dot(X, W) + np.repeat(
         np.reshape(b, (1, b.shape[0])), X.shape[0], axis=0)
     h = sigmoid(proj)
     residual = h - y
     loss = self._lossor.calculate(y, h)
     grad_W = 1. / nSize * np.dot(X.T, residual)
     grad_b = 1. / nSize * np.sum(residual)
     grad_parameter = roll_parameter([grad_W, grad_b])
     return loss, grad_parameter
 def predict(self, X):
     assert self._is_trained, 'model must be trained before predict.'
     pred = None
     _X = X
     if self._solve_type == 'numeric':
         if self._normalize is True:
             _X = copy.deepcopy(X)
             _X = (_X - self.Xmean) / self.Xstd
         nSize = _X.shape[0]
         param_list = unroll_parameter(self._parameter, self._parameter_shape)
         W, b = param_list[0], param_list[1]
         pred = np.dot(_X, W) + np.repeat(np.reshape(b, (1, b.shape[0])), _X.shape[0], axis=0)
     elif self._solve_type == 'analytic':
         pred = np.dot(_X, self._parameter['coef'])
     pred += self._norm_factor
     return pred