def run_linear_regression(self, x_axis, y_axis): self.x_axis = self.headers[x_axis] self.y_axis = self.headers[y_axis] self.slope = MathsUtil.estimate_slope(self.data[self.x_axis], self.data[self.y_axis]) self.y_intercept = MathsUtil.estimate_y_intercept(self.data[self.x_axis], self.data[self.y_axis], self.slope) self.predicted_y = MathsUtil.num_plus_arr(self.y_intercept, MathsUtil.num_by_arr(self.slope, self.data[self.x_axis]))
def test_number_by_array(self): self.assertEqual(MathsUtil.num_by_arr(0, [1, 2, 3]), [0, 0, 0]) self.assertEqual(MathsUtil.num_by_arr(2, [-1, -2, -3]), [-2, -4, -6]) self.assertEqual(MathsUtil.num_by_arr(-1, [-1, -2, -3]), [1, 2, 3]) self.assertEqual(MathsUtil.num_by_arr(2.5, [1.5, 2.4, 3.05]), [3.75, 6, 7.625])