Implement Linear regression over the dataset :param data_x : contains our dataset :param data_y : contains the output (result vector) :return : feature for line of best fit (Feature vector)
(data_x, data_y)
| 89 | |
| 90 | |
| 91 | def run_linear_regression(data_x, data_y): |
| 92 | """Implement Linear regression over the dataset |
| 93 | :param data_x : contains our dataset |
| 94 | :param data_y : contains the output (result vector) |
| 95 | :return : feature for line of best fit (Feature vector) |
| 96 | """ |
| 97 | iterations = 100000 |
| 98 | alpha = 0.0001550 |
| 99 | |
| 100 | no_features = data_x.shape[1] |
| 101 | len_data = data_x.shape[0] - 1 |
| 102 | |
| 103 | theta = np.zeros((1, no_features)) |
| 104 | |
| 105 | for i in range(iterations): |
| 106 | theta = run_steep_gradient_descent(data_x, data_y, len_data, alpha, theta) |
| 107 | error = sum_of_square_error(data_x, data_y, len_data, theta) |
| 108 | print(f"At Iteration {i + 1} - Error is {error:.5f}") |
| 109 | |
| 110 | return theta |
| 111 | |
| 112 | |
| 113 | def mean_absolute_error(predicted_y, original_y): |
no test coverage detected