What is the cost function? How do we minimize the cost function?

Cost function

cost function: Difference between actual output and expected output is called as cost function and the technique used to minimize cost function is called as gradient descent . for more details kindly go through this blog

Cost function is a generic term to provide al algorithm some sort of Metrics from comparison of negative connotations.

Let’s say you need to go from point A to point B and there are two possible roads you can use, X or Y. Suppose you divide each road in sections of 1 foot length.

the Cost function will add 1 each time you go from one section to the next. If X road is 10 feet, then the cost of reaching B is 10. If Y road is 15 feet, the cost function at point B through Y will be 15. Because you want to reach B through the shortest, least costly, route, you select the road that minimizes the results of the cost function, which in this case is road X.

The opposite to Cost function is Utility function.

Usually, you want to maximize utility and minimize cost.

Suppose that, in the same example, you want to select the longest road, for some reason. Then you maximize the result of applying the function and your algorithm will select road Y. It is the same formula but on the second case it is being used as a utility function.