def __init__(self): self.training_in, self.training_exp, self.test_in, self.test_exp = \ get_data(params['DATASET']) self.n_vars = np.shape(self.test_in)[1] if params['ERROR_METRIC'] == None: self.error = mse params['ERROR_METRIC'] = self.error else: self.error = params['ERROR_METRIC'] self.training_test = True
def __init__(self): # Get training and test data self.training_in, self.training_exp, self.test_in, self.test_exp = \ get_data(params['DATASET_TRAIN'], params['DATASET_TEST']) # Find number of variables. self.n_vars = np.shape(self.training_in)[0] # Regression/classification-style problems use training and test data. if params['DATASET_TEST']: self.training_test = True
def __init__(self): # Initialise base fitness function class. super().__init__() # Get training and test data self.training_in, self.training_exp, self.test_in, self.test_exp = \ get_data(params['DATASET_TRAIN'], params['DATASET_TEST']) # Find number of variables. self.n_vars = np.shape(self.training_in)[0] # Regression/classification-style problems use training and test data. if params['DATASET_TEST']: self.training_test = True
def __init__(self): # Initialise base fitness function class. super().__init__() # Get training and test data self.training_in, self.training_exp, self.test_in, self.test_exp = \ get_data(params['DATASET_TRAIN'], params['DATASET_TEST']) # Find number of variables. self.n_vars = np.shape(self.training_in)[0] # Regression/classification-style problems use training and test data. if params['DATASET_TEST']: self.training_test = True a = np.array([])
model = "ElasticNet int %.2f coefs %s" % (enet.intercept_, pprint(enet.coef_)) yhat_train = enet.predict(train_X) yhat_test = enet.predict(test_X) return model, yhat_train, yhat_test if __name__ == "__main__": dataset_name = sys.argv[1] if len(sys.argv) > 2: metric = sys.argv[2] else: metric = "rmse" s = "from .error_metric import " + metric + " as metric" exec(s) train_X, train_y, test_X, test_y = get_data(dataset_name) train_X = train_X.T test_X = test_X.T methods = [fit_maj_class, fit_const, fit_lr, fit_enet] for fit in methods: model, train_yhat, test_yhat = fit(train_X, train_y, test_X) error_train = metric(train_y, train_yhat) error_test = metric(test_y, test_yhat) print("%s %s %s train error %.2f test error %.2f" % (metric.__name__, fit.__name__, model, error_train, error_test))
enet.fit(train_X, train_y) model = "ElasticNet int %.2f coefs %s" % (enet.intercept_, pprint(enet.coef_)) yhat_train = enet.predict(train_X) yhat_test = enet.predict(test_X) return model, yhat_train, yhat_test if __name__ == "__main__": dataset_name = sys.argv[1] if len(sys.argv) > 2: metric = sys.argv[2] else: metric = "rmse" s = "from .error_metric import " + metric + " as metric" exec(s) train_X, train_y, test_X, test_y = get_data(dataset_name) train_X = train_X.T test_X = test_X.T methods = [fit_maj_class, fit_const, fit_lr, fit_enet] for fit in methods: model, train_yhat, test_yhat = fit(train_X, train_y, test_X) error_train = metric(train_y, train_yhat) error_test = metric(test_y, test_yhat) print("%s %s %s train error %.2f test error %.2f" % (metric.__name__, fit.__name__, model, error_train, error_test))