Difference between loss function and cost function

Updated May 15, 2026

Short answer

Loss is per sample error; cost is averaged over dataset.

Deep explanation

Loss function computes error for a single data point, while cost function aggregates losses over the entire dataset. In batch training, cost function guides parameter updates across all samples.

Real-world example

In spam detection, loss is per email, cost is over all emails.

Common mistakes

  • Using terms interchangeably in strict mathematical contexts.

Follow-up questions

  • Can loss and cost ever be identical?
  • Why do we average cost?

More Cost Function interview questions

View all →