def predict(self, x): """ Predict the output given an input array :param x: input data :return: predicted values """ pol = pps.pps_basis(x, self.model['order']) return np.dot(pol, self.model['weights'])
def train(self, x, y, l2_term=0, method='closed'): """ Train the PPS Regression model :param x: input data :param y: output data :param l2_term: regularization term :param method: optimization method """ # train using the closed form if method == 'closed': # generate the sigmoid polynomial H = pps.pps_basis(x, self.model['order']) H_t = np.transpose(H) # apply the regularization term regularizer = np.identity(self.model['order'] + 1) * l2_term A = linalg.inv(np.dot(H_t, H) + regularizer) # compute the best parameters self.model['weights'] = np.dot(np.dot(A, H_t), y)