Types of loss function

Types of loss function

📘 Types of Loss Functions in Machine Learning

Loss functions measure how well a model’s predictions match the actual data. They guide the training process by minimizing errors.


Used when predicting continuous values (e.g., prices, temperatures).

Loss FunctionDescription
MSE (Mean Squared Error)Squares the errors. Penalizes larger errors more.
MAE (Mean Absolute Error)Uses absolute differences. Less sensitive to outliers.
Huber LossMix of MSE and MAE. More robust to outliers.

Used when predicting categories or labels.

Loss FunctionDescription
Binary CrossentropyFor binary classification (0 or 1).
Categorical CrossentropyFor multi-class classification (one-hot encoded labels).
Sparse Categorical CrossentropyFor multi-class classification (integer labels).

Used for ranking tasks, reinforcement learning, or sequence models.

Loss FunctionDescription
Hinge LossUsed in SVMs. Encourages correct class margin.
Triplet LossUsed for similarity learning (e.g., face recognition).
KL DivergenceMeasures difference between two probability distributions.
CTC LossFor sequence problems with unaligned input/output (e.g., speech).

  • Use MSE or MAE for regression.
  • Use Crossentropy for classification.
  • Use Triplet, Hinge, or CTC for more advanced tasks.