Skip to content

Commit ffd18e0

Browse files
committed
Updated code as per PR feedback 6
1 parent d564698 commit ffd18e0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

machine_learning/ridge_regression.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import numpy as np
23
from matplotlib import pyplot as plt
34
from sklearn import datasets
@@ -27,7 +28,7 @@ def ridge_cost_function(x: np.ndarray, y: np.ndarray, theta: np.ndarray, alpha:
2728
m = len(y)
2829
predictions = np.dot(x, theta)
2930
cost = (1 / (2 * m)) * np.sum((predictions - y) ** 2) + \
30-
(alpha / 2) * np.sum(theta[1:] ** 2)
31+
(alpha / 2) * np.sum(theta[1:] ** 2)
3132

3233
return cost
3334

@@ -61,8 +62,6 @@ def ridge_gradient_descent(x: np.ndarray, y: np.ndarray, theta: np.ndarray, alph
6162

6263
return theta
6364

64-
65-
6665
if __name__ == "__main__":
6766
import doctest
6867
doctest.testmod()
@@ -90,6 +89,7 @@ def ridge_gradient_descent(x: np.ndarray, y: np.ndarray, theta: np.ndarray, alph
9089
# Prediction
9190
def predict(x, theta):
9291
return np.dot(x, theta)
92+
9393
y_pred = predict(x, optimized_theta)
9494

9595
# Plotting the results (here we visualize predicted vs actual values)
@@ -101,3 +101,4 @@ def predict(x, theta):
101101
plt.title("Ridge Regression: Actual vs Predicted Values")
102102
plt.legend()
103103
plt.show()
104+

0 commit comments

Comments
 (0)