Intermediate Topic 19 of 51 AI & Machine Learning
Loss Functions
Quantities measuring how wrong predictions are.
How it works
A loss function measures how far a model's predictions are from the targets, giving a single number the training procedure tries to minimize. Common choices include mean squared error and mean absolute error for regression, Huber loss for robustness, binary and categorical cross-entropy for classification, hinge loss for support vector machines and specialized losses for ranking, segmentation and generative models. The choice shapes what the model learns and how gradients behave.
Step-by-step walkthrough
- A loss measures how wrong a prediction is.
- Squared error is used for regression.
- Cross-entropy is used for classification probabilities.
- Hinge loss is used by support vector machines.
- Training minimizes the average loss.
Where it is used
Every trained model has a loss: cross-entropy for classifiers, MSE for forecasts, contrastive losses for embeddings and adversarial losses for GANs.
Common pitfall
The loss that is easy to optimize may differ from the metric you care about, such as accuracy, which is not differentiable. Squared error is sensitive to outliers. Class imbalance may need weighted losses. Numerical issues such as log of zero need stable implementations like logits with built-in softmax. Choose a loss that matches the task and monitor both loss and metrics.
Where it fits in the course
Loss Functions is topic 19 of 51 in AI & Machine Learning, rated Intermediate. It follows Gradient Descent. The next topic is Regularization.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the AI & Machine Learning quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the AI & Machine Learning quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Loss Functions?
Where do people use Loss Functions?
What is the most common mistake with Loss Functions?
What should I learn before this topic?
How can I practice it?
Is Loss Functions hard to learn?
How long does it take to learn Loss Functions?
Which topics are related to Loss Functions?
What should I study after Loss Functions?
Related topics
- Gradient Descent (AI & Machine Learning)
- Regularization (AI & Machine Learning)
- Cross-Validation (AI & Machine Learning)
- Naive Bayes (AI & Machine Learning)
- Functions and Relations (Theory & Discrete Math)
- Functions and Graphs (Math for Computing)
- Functions (Programming Fundamentals)