> For the complete documentation index, see [llms.txt](https://vikram-bajaj.gitbook.io/machine-learning-stanford-coursera/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vikram-bajaj.gitbook.io/machine-learning-stanford-coursera/supervised-learning/linear-regression/linear-regression-in-one-variable/cost-function.md).

# Cost Function

We can measure the **accuracy** of our hypothesis function by using a cost function. This takes an average (actually a fancier version of an average) of all the results of the hypothesis with inputs from x's compared to the actual output y's.

If m is the number of training examples, the cost function for *Linear Regression in One Variable* is given by:

$$J(θ\_0,θ\_1) = (1/2m) ∑\_{i=1}^{m}(h\_θ(x^{(i)})−y^{(i)})^2$$

Lower values indicate more accuracy.

This function is otherwise called the "Squared error function", or Mean squared error.

We can plot it on a graph taking $$θ\_0$$ and $$θ\_1$$ on the x and z axis respectively, and J on the y axis:

![](https://1423730981-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M5-0RGuSGVoyMc2kCFR%2F-M5-0RgMLg-NeST4zMsc%2F-M5-0U6bc4M50NCGyiY6%2FLinearRegression_CostFn.PNG?generation=1586990807665570\&alt=media)
