Gradient Descent From First Principles

🔖

1. Supervised Learning & Loss Functions · ⏱ 3 min read
SHARE

How Models Learn From Error Gradients

Gradient descent updates model parameters in the opposite direction of the loss gradient: $w \leftarrow w - \eta \frac{\partial L}{\partial w}$, where $\eta$ is the learning rate.

Important Choosing the Learning Rate $\eta$ If $\eta$ is too small, convergence is slow; if $\eta$ is too large, updates overshoot the minimum and diverge.

Example
# Minimize L(w) = (w - 3.5)^2 using gradient descent
w = 0.0
learning_rate = 0.25

for step in range(1, 8):
    grad = 2.0 * (w - 3.5)
    w = w - learning_rate * grad
    loss = (w - 3.5) ** 2
    print(f"Step {step}: w = {w:.4f}, Loss = {loss:.5f}")

Track your progress

Sign in to save progress →

Type 2 or more letters to search all learning resources...