Introducing the concept with my new comic!

Prerequisites: ML basics such as types of ML algorithms and linear regression.
What is a cost function?
The cost function measures the degree to which the predicted values align with the actual values. It helps in optimizing the model's function to produce better results.
Calculation
Let's assume a linear regression model.
Where hypothesis is defined as:
where,
hθ(x) - hypothesis function
θ0 - intercept term
θ1- slope coefficient
x - input variable
According to the definition,
Cost function= hθ(x) - yi ( predicted value - actual value)
However for precision, it is generally calculated as the mean squared error (MSE) between predicted and actual values.
So,
Where,
Summation - The MSE applies to all the M training examples.
Squaring ensures that the positive and negative terms don't cancel each other.
The equation is multiplied by 1/2M for normalization and simplification during derivative application.
Final equation for cost function is:
The above equation is then minimized using gradient descent to minimize the loss.
I'll explain the gradient descent calculations in the next blog :)