Skip to content

Loss Functions in Machine Learning

How loss functions define what a model optimises, and common choices for regression, classification and ranking.

Editorial team 1 min read

A loss function measures how wrong a model's predictions are. Training adjusts parameters to reduce it, so the choice shapes what the model learns.

Regression Losses

  • Mean squared error: penalises large errors heavily.
  • Mean absolute error: more robust to outliers.
  • Huber loss: squared for small errors, absolute for large — a compromise.
  • Quantile loss: for predicting percentiles and ranges.

Classification Losses

  • Binary cross-entropy (log loss): for yes-or-no predictions.
  • Categorical cross-entropy: for multi-class problems.
  • Focal loss: focuses on hard examples, useful for imbalanced data.
  • Hinge loss: used by support vector machines.

Other Losses

  • Contrastive and triplet losses: for learning embeddings where similar items are close.
  • Ranking losses: for search and recommendation.

Loss Versus Metric

The loss is what training optimises; the metric is what you care about. They should be aligned, but they're not always the same — you might train with cross-entropy but evaluate with F1.

Custom Losses

Weighting errors by business cost can align training with real outcomes.

More in Machine learning

All Machine learning guides →
Machine learning Guide · 2 min

Linear Regression Explained

The simplest predictive model: how linear regression fits a line through data, how to read its coefficients, and when it breaks down.

Machine learning 2 min read 17 Sep 2026

Machine learning Guide · 2 min

Logistic Regression for Classification

Despite its name, logistic regression is a classification method. How it produces probabilities and why it remains a strong baseline.

Machine learning 2 min read 16 Sep 2026

Machine learning Guide · 2 min

Decision Trees

How decision trees split data with simple questions, why they are easy to explain, and why single trees overfit.

Machine learning 2 min read 15 Sep 2026

Machine learning Guide · 2 min

Random Forests

Why averaging many randomised decision trees produces a robust, accurate model with little tuning.

Machine learning 2 min read 14 Sep 2026