# Cost Function

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

$J(θ_{0},θ_{1})=mi=∑m(y^_{i}−y_{i})_{2}=mi=∑m(h_{θ}(x_{i})−y_{i})_{2}$

To break it apart, it is $21$ $xˉ$ where $xˉ$ is the mean of the squares of $h_{θ}(x_{i})−y_{i}$ , or the difference between the predicted value and the actual value.

This function is otherwise called the “Squared error function”, or “Mean squared error”. The mean is halved $(21)$ as a convenience for the computation of the gradient descent, as the derivative term of the square function will cancel out the $21$ term. The following image summarizes what the cost function does: