A loss function, also called a cost function, measures the difference between the predicted output of a machine learning model and the true output, which is used to optimize the model's parameters during training. They are the function we are trying to train a model to minimize.