Skip to content

Commit b6224ec

Browse files
fix: return sum of squared errors (#15272)
1 parent 742f939 commit b6224ec

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

machine_learning/linear_regression.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,22 @@ def run_steep_gradient_descent(data_x, data_y, len_data, alpha, theta):
6767
return theta
6868

6969

70-
def sum_of_square_error(data_x, data_y, len_data, theta):
70+
def sum_of_square_error(data_x, data_y, theta):
7171
"""Return sum of square error for error calculation
7272
:param data_x : contains our dataset
7373
:param data_y : contains the output (result vector)
74-
:param len_data : len of the dataset
7574
:param theta : contains the feature vector
7675
:return : sum of square error computed from given feature's
7776
7877
Example:
7978
>>> vc_x = np.array([[1.1], [2.1], [3.1]])
8079
>>> 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)
80+
>>> round(sum_of_square_error(vc_x, vc_y, np.array([1])), 3)
81+
np.float64(0.03)
8382
"""
8483
prod = np.dot(theta, data_x.transpose())
8584
prod -= data_y.transpose()
86-
sum_elem = np.sum(np.square(prod))
87-
error = sum_elem / (2 * len_data)
88-
return error
85+
return np.sum(np.square(prod))
8986

9087

9188
def run_linear_regression(data_x, data_y):
@@ -104,7 +101,7 @@ def run_linear_regression(data_x, data_y):
104101

105102
for i in range(iterations):
106103
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)
104+
error = sum_of_square_error(data_x, data_y, theta)
108105
print(f"At Iteration {i + 1} - Error is {error:.5f}")
109106

110107
return theta

0 commit comments

Comments
 (0)