# find the values of theta in a cost function from andrew ng course

I was following Andrew NG ML course on coursera. I was stuck at cost function.

How can I find values for Theta-0 and Theta-1 ?

So I came to know Theta-0 as y intercept so the values must be Theta-0 = 0.5 but how can I find the value for Theta-1?

Any help is appreciated.

• $\theta_1$ is the slope, which can be eyeballed to be 1, since your line increases by 1 for every 1 increase in x. Dec 6, 2018 at 12:19

Elaborating on the previous answer, now hat you have $$\theta_0 = 0.5$$, take any value of $$x$$ and the corresponding $$h_\theta$$ value to find $$\theta_1$$. For instance, using $$x=1$$ will yield:

$$h_\theta(1) = \theta_0 + \theta_1 \times 1$$

From the graphd, $$h_\theta(1) = 1.5$$ so that:

$$\theta_0 + \theta_1 = 1.5$$

$$\theta_1 = 1.5 - \theta_0$$

$$\theta_1 = 1.5 - 0.5 = 1$$

The final equation is then $$h_\theta = 0.5 + x$$

As said in the comment, you can also get the slope visually, noticing that if you increase $$x$$ by 1, $$y$$ also increases by 1 when you follow the slope.

Does this help?