MCPcopy
hub / github.com/TheAlgorithms/Python / run_linear_regression

Function run_linear_regression

machine_learning/linear_regression.py:91–110  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

89
90
91def 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
113def mean_absolute_error(predicted_y, original_y):

Callers 1

mainFunction · 0.85

Calls 2

sum_of_square_errorFunction · 0.85

Tested by

no test coverage detected