Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Initial Commit
  • Loading branch information
preethamak authored Oct 13, 2025
commit 1359e5926a99e172fd3b5415398da559fa97a2f9
17 changes: 17 additions & 0 deletions 43. Ridge Regression Loss Function
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import numpy as np

def ridge_loss(X: np.ndarray, w: np.ndarray, y_true: np.ndarray, alpha: float) -> float:
# Your code here
x = np.array(X)
w = np.array(w)
y_true = np.array(y_true)

y_pr = x @ w

loss = np.mean((y_pr - y_true)**2)

reg = alpha * np.sum(w**2)

final_loss = loss + reg

return final_loss