> 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:

![](/files/-M5-0U6bc4M50NCGyiY6)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vikram-bajaj.gitbook.io/machine-learning-stanford-coursera/supervised-learning/linear-regression/linear-regression-in-one-variable/cost-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
