def test_init_empty(self): # self.isinit_sheet_success(Frame(), [], (0, 0), [], None, []) self.isinit_sheet_success(SeriesSet(nan=None), OrderedDict(), (0, 0), [], None, []) # self.isinit_sheet_success(Frame(columns=['A', 'B']), [], (0, 2), ['A', 'B'], None, [0, 0]) self.isinit_sheet_success(SeriesSet(columns=['A', 'B'], nan=None), OrderedDict(A=Series([]), B=Series([])), (0, 2), ['A', 'B'], None, [0, 0])
def __init__(self, engine, learn_rate, l1_penalty, l2_penalty): BaseEngineModel.__init__(self, engine) self.learn_rate = learn_rate self.l1_penalty = l1_penalty self.l2_penalty = l2_penalty self._activator = Activators(self.engine) self._accuracy = None self._cost_history = Series() # Mistake Recorder
def transform(self, X_mat, stochastic_matrix=None, min_error=0.0001, max_iter=1000): X_mat = self._mat(X_mat).T if stochastic_matrix is False: weight = self._weight self._weight = weight = self._mat(stochastic_matrix) assert isinstance(max_iter, int) and max_iter >= 1 assert X_mat.shape[1] == 1, 'X should be 1-D sequence' assert X_mat.shape[0] == weight.shape[ 1], 'items in the X not fit the shape of weight matrix' for round_ in range(max_iter): X_next = self._alpha * self._dot( weight, X_mat) + (1.0 - self._alpha) / X_mat.shape[0] error = self._sum(self._abs(X_next - X_mat)) X_mat = X_next if error < min_error: LogInfo(' Early stopped iteration') break return Series(X_mat.T.tolist()[0])
def predict(self, X): assert X.shape[1] == self.n_features return Series(self.predict_once(row) for row in X)