2

I am new to machine learning and statistics and am confused with the cost function & Mean Squared Error (MSE) formulas. In Machine learning class at stanford - coursera, Cost function formula is mentioned as shown below:

Cost Function formula

enter image description here

And at some other sources, cost function is termed as mean squared error (MSE) and it is given with the formula as shown in picture below.

Mean Squared Error formula

enter image description here

What will be the Cost Function formula & is cost function and MSE different or same. Please let me know why are the formulas are different.

Thanks in Advance

Raj

1 Answer 1

3

The cost function is just telling you how bad you're doing. If it's high, that means your prediction is far away from the actual value. if it's zero, it means that you are predicting every single output correctly. In coursera version the sigma term is divided by 2m and in the other version it is divided by m (m is the number of training examples). It doesn't matter in what the cost function is doing, since m is just a constant. Dividing by 2m is just a mathematical convenience. For example, if the sigma term is 100 and m is 10, cost function in coursera version is going to be 5 and in the other version it's going to be 10. Since you're trying to make cost function 0, it doesn't matter what value it returns. You just need a tool to measure how bad you're doing.

3
  • Your welcome. I would appreciate it if you accept my answer and vote it. May 22, 2018 at 1:27
  • Thank you and I got your point. Cost function is given by = 1/ 2m * Summation of (h(x) - y)^2; where h(x)= theta0 + theta1*x or h(x)= a+bx. & in the MSE formula it is given as 1 / m * Summation of (y - h(x))^2; where h(x)= theta0 + theta1*x or h(x)= a+bx. In the summation part, why it is different. Is it (h(x) - y)^2 or (y - h(X))^2.
    – rajd216
    May 22, 2018 at 1:30
  • h(x) is your prediction an y is the actual value. Both of those formulas find the difference and them square it. Since they're squared, both of them are identical. For example, let's say y=3 and h(x)=5. Then the resul of those formulas are going to be 2 and -2. You can see that when we both of them, the result is 4. May 22, 2018 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.