1. **State the problem:** We have data points $x = [1, 2, 3]$ and $y = [1, 3, 5]$. Initial parameters are $\theta_0 = 0$ and $\theta_1 = 0$. Learning rate $\alpha = 0.1$. We want to find the cost function $J(\theta)$ after the first iteration of Gradient Descent.
2. **Recall formulas:**
- Cost function: $$J(\theta) = \frac{1}{2m} \sum_{i=1}^m (h_\theta(x^{(i)}) - y^{(i)})^2$$
- Hypothesis: $$h_\theta(x) = \theta_0 + \theta_1 x$$
- Gradient Descent update rules:
$$\theta_0 := \theta_0 - \alpha \frac{1}{m} \sum_{i=1}^m (h_\theta(x^{(i)}) - y^{(i)})$$
$$\theta_1 := \theta_1 - \alpha \frac{1}{m} \sum_{i=1}^m (h_\theta(x^{(i)}) - y^{(i)}) x^{(i)}$$
3. **Calculate initial hypothesis values:**
Since $\theta_0=0$ and $\theta_1=0$, for each $x^{(i)}$:
$$h_\theta(x^{(i)}) = 0 + 0 \times x^{(i)} = 0$$
4. **Calculate errors:**
$$h_\theta(x^{(i)}) - y^{(i)} = 0 - y^{(i)} = -y^{(i)}$$
So errors are $[-1, -3, -5]$.
5. **Update $\theta_0$:**
$$\theta_0 := 0 - 0.1 \times \frac{1}{3} (-1 -3 -5) = 0 - 0.1 \times \frac{-9}{3} = 0 - 0.1 \times (-3) = 0 + 0.3 = 0.3$$
6. **Update $\theta_1$:**
Calculate $\sum (h_\theta(x^{(i)}) - y^{(i)}) x^{(i)} = (-1)\times1 + (-3)\times2 + (-5)\times3 = -1 -6 -15 = -22$
$$\theta_1 := 0 - 0.1 \times \frac{-22}{3} = 0 - 0.1 \times (-\frac{22}{3}) = 0 + \frac{2.2}{3} = 0.7333$$
7. **Calculate new hypothesis values with updated parameters:**
$$h_\theta(x^{(i)}) = 0.3 + 0.7333 x^{(i)}$$
For $x=1$: $0.3 + 0.7333 \times 1 = 1.0333$
For $x=2$: $0.3 + 0.7333 \times 2 = 1.7666$
For $x=3$: $0.3 + 0.7333 \times 3 = 2.4999$
8. **Calculate squared errors:**
$$(h_\theta(x^{(i)}) - y^{(i)})^2$$
For $i=1$: $(1.0333 - 1)^2 = 0.0011$
For $i=2$: $(1.7666 - 3)^2 = 1.5222$
For $i=3$: $(2.4999 - 5)^2 = 6.2501$
9. **Calculate cost function:**
$$J(\theta) = \frac{1}{2 \times 3} (0.0011 + 1.5222 + 6.2501) = \frac{1}{6} (7.7734) = 1.2956$$
**Final answer:** The cost function after the first iteration is approximately $1.2956$.
Gradient Descent Cost Ef0Fd3
Step-by-step solutions with LaTeX - clean, fast, and student-friendly.