Linear Regression with Gradient Descent

30%
Data Points
Current Regression Line
True Relationship
Slope (θ₁)
0.00
Intercept (θ₀)
0.00
Cost (J(θ))
0.00
Iteration
0
Click "Generate New Data" to create random data points, then "Run Gradient Descent" to start the optimization.

How Gradient Descent Works for Linear Regression

Linear Regression Model

The model predicts: hθ(x) = θ₀ + θ₁x

Cost Function (Mean Squared Error)

J(θ) = 1/(2m) ∑i=1m (hθ(x(i)) - y(i))2

Gradient Descent Algorithm

Repeat until convergence:

θj := θj - α ∂J(θ)/∂θj (for j = 0,1)

Partial Derivatives

∂J(θ)/∂θ₀ = 1/m ∑i=1m (hθ(x(i)) - y(i))

∂J(θ)/∂θ₁ = 1/m ∑i=1m (hθ(x(i)) - y(i))x(i)

Key Parameters