Return sum of square error for error calculation :param data_x : contains our dataset :param data_y : contains the output (result vector) :param len_data : len of the dataset :param theta : contains the feature vector :return : sum of square error computed fro
(data_x, data_y, len_data, theta)
| 68 | |
| 69 | |
| 70 | def sum_of_square_error(data_x, data_y, len_data, theta): |
| 71 | """Return sum of square error for error calculation |
| 72 | :param data_x : contains our dataset |
| 73 | :param data_y : contains the output (result vector) |
| 74 | :param len_data : len of the dataset |
| 75 | :param theta : contains the feature vector |
| 76 | :return : sum of square error computed from given feature's |
| 77 | |
| 78 | Example: |
| 79 | >>> vc_x = np.array([[1.1], [2.1], [3.1]]) |
| 80 | >>> vc_y = np.array([1.2, 2.2, 3.2]) |
| 81 | >>> round(sum_of_square_error(vc_x, vc_y, 3, np.array([1])),3) |
| 82 | np.float64(0.005) |
| 83 | """ |
| 84 | prod = np.dot(theta, data_x.transpose()) |
| 85 | prod -= data_y.transpose() |
| 86 | sum_elem = np.sum(np.square(prod)) |
| 87 | error = sum_elem / (2 * len_data) |
| 88 | return error |
| 89 | |
| 90 | |
| 91 | def run_linear_regression(data_x, data_y): |
no test coverage detected