Skip to content

Commit cb783fe

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 7ea2f66 commit cb783fe

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

machine_learning/01_linear_regression.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22

3+
34
# -------------------- Naive Linear Regression --------------------
45
def naive_linear_regression(X, y, learning_rate=0.01, epochs=1000):
56
"""
@@ -27,6 +28,7 @@ def naive_linear_regression(X, y, learning_rate=0.01, epochs=1000):
2728
theta[j][0] -= learning_rate * grad / m
2829
return theta
2930

31+
3032
# -------------------- Vectorized Linear Regression --------------------
3133
def vectorized_linear_regression(X, y, learning_rate=0.01, epochs=1000):
3234
"""
@@ -41,11 +43,12 @@ def vectorized_linear_regression(X, y, learning_rate=0.01, epochs=1000):
4143
theta -= learning_rate * gradient
4244
return theta
4345

46+
4447
# -------------------- Test Both Implementations --------------------
4548
if __name__ == "__main__":
4649
# Sample dataset
4750
X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
48-
y = np.dot(X, np.array([[1],[2]])) + 3 # y = 1*x1 + 2*x2 + 3
51+
y = np.dot(X, np.array([[1], [2]])) + 3 # y = 1*x1 + 2*x2 + 3
4952

5053
theta_naive = naive_linear_regression(X, y)
5154
theta_vec = vectorized_linear_regression(X, y)

0 commit comments

Comments
 (0)