Gradient Descent
An iterative optimization algorithm that adjusts model parameters step by step, moving in the direction that most reduces the loss function.
- Compute the gradient (slope) of the loss with respect to each parameter
- Update each parameter: param -= learning_rate * gradient
- Repeat until the loss stops improving meaningfully
- Learning rate too high → overshoots/diverges; too low → painfully slow convergence
for epoch in range(epochs):
predictions = X.dot(weights)
error = predictions - y
gradient = X.T.dot(error) / len(X)
weights -= learning_rate * gradient