A blog for computer science passionates.

Wednesday, 27 May 2020

What is Cost Function? A Gentle Introduction

Hello Friends!!!
Welcome to passionforcs,

Once upon a time I played a game especially puzzle and I tried to solve it. And of course, I solved :) (Kidding) but I solved, and my friend asked me how much time did you spent to solve this puzzle? And I got stuck & went in deep thinking of Machine Learning.

When we train our model, at that time also we should think about how our model performs? we can do this by using cost function to check whether our model performs well or not. Our hypothesis is valid and true so that the model gets the appropriate prediction or not.
In simple words the main usage of the cost function is after getting the prediction, how far or close our predicted values are from the actual values (i.e. label y).

Let's first prove these words by using the simple example.

Suppose our model predict a price of a share A, So the price of the share A for today is around 410 this is the prediction and the actual value of the share A is 415 so the difference between the actual value and predicted value is 5, but if our predicted value is 450 and actual price is 400 of the share A then the difference between these two is 50.

When the difference is 5 we can say our model works fine for the share A, but when the difference is too high such as 50, our model doesn't predict well.

This is the cost function. When we build a model, we have to check the cost function to find whether our model performs well or not. A cost of a good model should be minimum.
Difference between predicted and actual value of Share Price
NOTE: THIS FIGURE IS NOT PERFECT, THIS IS JUST AN EXAMPLE TO SHOW THE ACTUAL CONCEPT.

So, through the above figure, we can get that blue dot is actual value, red square is predicted values and dark blue triangle is the difference but if difference is too big, the model doesn't predict well.

Hope you enjoy this article, Stay Home, Stay Safe.


No comments:

Post a Comment