A loss function is a function that quantifies the error between a model's predictions and the actual values. In machine learning and deep learning, it is used to evaluate a model's performance and to optimize it. The smaller the loss, the closer the model's predictions are judged to be to the true values. In theory, the loss function is used by optimization algorithms (e.g., stochastic gradient descent (SGD) and Adam) as the guide for updating the model's parameters. Common loss functions include mean squared error (MSE), cross-entropy loss, and hinge loss, each designed for particular tasks. In this way, the loss function plays a key role in training: by minimizing the error, it helps the model make more accurate predictions.
The figure below shows how the three loss functions mentioned above grow as the prediction deviates.


