def RunLinearRegressionMlpy(q): totalTimer = Timer() # Load input dataset. # If the dataset contains two files then the second file is the test file. Log.Info("Loading dataset", self.verbose) if len(self.dataset) >= 2: test_data = np.genfromtxt(self.dataset[1], delimiter=',') # Use the last row of the training set as the responses. X, y = SplitTrainData(self.dataset[0]) try: with totalTimer: # Perform linear regression. model = mlpy.OLS() model.learn(X, y) b = model.beta() if len(self.dataset) >= 2: #prediction on the test data. pred = model.pred(test_data) except Exception as e: q.put(-1) return -1 time = totalTimer.ElapsedTime() q.put(time) if len(self.dataset) >= 2: np.savetxt("mlpy_lr_predictions.csv", pred, delimiter="\n") return time
def RunLinearRegressionMlpy(q): totalTimer = Timer() # Load input dataset. # If the dataset contains two files then the second file is the responses # file. Log.Info("Loading dataset", self.verbose) if len(self.dataset) == 2: X = np.genfromtxt(self.dataset[0], delimiter=',') y = np.genfromtxt(self.dataset[1], delimiter=',') else: X = np.genfromtxt(self.dataset, delimiter=',') y = X[:, (X.shape[1] - 1)] X = X[:,:-1] try: with totalTimer: # Perform linear regression. model = mlpy.OLS() model.learn(X, y) b = model.beta() except Exception as e: q.put(-1) return -1 time = totalTimer.ElapsedTime() q.put(time) return time
def __init__(self, file_name, flag): if flag == "ridge": self.lrs = [mlpy.Ridge() for i in range(7)] else: self.lrs = [mlpy.OLS() for i in range(7)] self.file_name = file_name self.x_weekday = dict() self.y_weekday = dict()
def regression_linear(x,y): ''' Estimate a linear regression ''' # create the model object ols = ml.OLS() # estimate the model ols.learn(x, y) # and return the fit model return ols
def BuildModel(self, data, responses): # Create and train the classifier. model = mlpy.OLS() model.learn(data, responses) return model