def setUp(self): cols = ['GarageArea', 'OverallQual', 'BldgType'] self.dataset = io_tools.read_dataset("data/train.csv") self.processed_data = data_tools.preprocess_data(self.dataset, feature_columns=cols) self.N = self.processed_data[0].shape[0] self.ndims = self.processed_data[0].shape[1] self.model = linear_regression.LinearRegression(self.ndims, "zeros")
def sarcos_linear_regression(): X_train, Y_train, X_cv, Y_cv, X_test, Y_test = data.get_data_split( [0.6, 0.2, 0.2], normalize=True) print('Linear regression, sarcos:') print('\tThis will take about 5 seconds, please wait...') model = linear_regression.LinearRegression(X_train, Y_train) model.train(10000, 0.1, print_iterations=False) rmse, prediction = model.test(X_test, Y_test) rmse_train, _ = model.test(X_train, Y_train) print('\tRMSE: ' + str(rmse))
def test_total_loss(self): self.model = linear_regression.LinearRegression(2, 'zeros', w_decay_factor=0.1) self.model.w = np.array([[2], [-2]]) y = np.array([[1], [1], [1], [-1], [-1], [-1]]) f = np.array([[0.5], [0], [0.5], [-1], [-1], [-1]]) loss = self.model.total_loss(f, y) self.assertEqual(round(loss, 5), 0.5 * (0.5**2. + 1 + 0.5**2. + 0 + 0 + 8 * 0.1))
def setUp(self): self.model = linear_regression.LinearRegression(5, 'zeros')
def test_init_ones(self): self.model = linear_regression.LinearRegression(5, 'ones') np.testing.assert_array_equal(np.ones((6, 1)), self.model.w)
def test_uniform_init(self): self.model = linear_regression.LinearRegression(5, 'uniform') np.testing.assert_equal( np.any(np.equal(np.zeros((6, 1)), self.model.w)), False)
def setUp(self): self.model = linear_regression.LinearRegression(5, 'uniform')