The cost function is a function that describes how well a machine learning algorithm approximates some function , or, in other words, how close our algorithm is at achieving its main purpose of predicting the output based on a given input.
Most of the time the cost function being used is the cross-entropy between the training data and the model’s predictions.