def calculate_alpha_s(self, weak_learner, s): alpha = 0.0 new_s = s data_num = len(weak_learner.train_Y) X = [] for i in range(data_num): predict_string = np.array(list(map(str, weak_learner.train_X[i]))) predict_string = ' '.join(predict_string[1:]) + ' ' + str(weak_learner.train_Y[i]) prediction = weak_learner.prediction(predict_string, 'test_data') X.append([float(prediction['prediction'])]) X = np.array(X) linear = linear_regression.LinearRegression() linear.status = 'load_train_data' linear.train_X = X linear.train_Y = weak_learner.train_Y - s linear.set_param() linear.init_W() linear.train() alpha = linear.W[0] new_s = s + alpha * np.ravel(X) return alpha, new_s
def train(self): predict_X = [] for x in self.models[0].train_X: x_string = ' '.join(map(str, x.tolist()[1:])) transform_x = self.feature_transform(x_string) transform_x.insert(0, 1) predict_X.append(transform_x) self.linear = linear_regression.LinearRegression() self.linear.load_train_data() self.linear.load_test_data() self.linear.train_X = np.array(predict_X) self.linear.train_Y = self.models[0].train_Y self.linear.set_param() self.linear.init_W() self.linear.train()