def train(self):
if (self.status != '<STR_LIT>'):<EOL><INDENT>print("<STR_LIT>")<EOL>return self.W<EOL><DEDENT>self.status = '<STR_LIT:train>'<EOL>for i in range(<NUM_LIT:0>, self.updates):<EOL><INDENT>if self.feed_mode == '<STR_LIT>':<EOL><INDENT>stochastic_i = random.randint(<NUM_LIT:0>, self.data_num - <NUM_LIT:1>)<EOL>x = self.train_X[stochastic_i]<EOL>y = self.train_Y[stochastic_i]<EOL>gradient = self.calculate_gradient(x, y, self.W)<EOL><DEDENT>else:<EOL><INDENT>gradient = self.calculate_gradient(self.train_X, self.train_Y, self.W)<EOL><DEDENT>if np.linalg.norm(gradient) == <NUM_LIT:0>:<EOL><INDENT>return self.W<EOL><DEDENT>self.W = self.W - self.step_eta * gradient<EOL><DEDENT>return self.W<EOL>
Train Linear Regression Algorithm
From f(x) = WX
Find best h(x) = WX similar to f(x)
Output W

mode: batch / stochastic