A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Loss Functions and Objective Functions

Graduate Depth 97 in the knowledge graph ☐ I know this ☆ Set as goal
4topics build on this
674prerequisites beneath it
See this on the map →
Gradient Descent and OptimizationNeural Network Fundamentals+2 more→→Optimization Algorithms: SGD, Adam, RMSprop
loss objective training

Core Idea

Loss functions quantify the error between predicted outputs and actual targets, defining what the model learns to minimize during training. Common choices include mean squared error for regression, cross-entropy for classification, and Huber loss for robustness to outliers. Selecting an appropriate loss function directly shapes model behavior and final performance.

How It's Best Learned

Implement MSE, cross-entropy, and Huber loss from scratch. Compare convergence on toy datasets; observe how different losses affect learning dynamics.

Common Misconceptions

Loss and accuracy are distinct metrics; optimizing loss does not guarantee optimal accuracy. Not all problems suit standard losses; domain knowledge may suggest custom objectives.

Explainer

You already know that a neural network adjusts its weights through gradient descent — but gradient descent needs a direction, and the loss function is what provides it. A loss function takes the model's prediction and the true target, and returns a single number measuring how wrong the prediction is. Training then becomes an optimization problem: find the weights that minimize this number across the dataset. The choice of loss function is not a technicality — it defines what "wrong" means, and different definitions lead to fundamentally different model behaviors.

For regression tasks, the most common choice is mean squared error (MSE), which computes the average of the squared differences between predictions and targets. Squaring amplifies large errors, so MSE-trained models aggressively penalize big mistakes. This is useful when outliers genuinely matter, but problematic when your data contains noise or extreme values you would rather downweight. Mean absolute error (MAE) treats all errors linearly and is more robust to outliers, but its gradient is constant regardless of error size, which can make optimization less smooth. The Huber loss blends both: it behaves like MSE for small errors (smooth gradients near the minimum) and like MAE for large errors (bounded influence of outliers), controlled by a threshold parameter delta.

For classification, the standard is cross-entropy loss, which measures the divergence between the predicted probability distribution and the true label distribution. If your model predicts a probability of 0.9 for the correct class, the loss is small; if it predicts 0.01, the loss is very large. Cross-entropy has a crucial property: its gradient with respect to the output logits is simply the difference between predicted and true probabilities, which connects directly to the partial derivatives you have studied. This clean gradient signal is why cross-entropy trains faster and more reliably than alternatives like MSE applied to classification outputs.

Understanding the relationship between loss and evaluation metrics is essential. Loss is what the model optimizes; metrics like accuracy, precision, or F1 are what you care about. These are not the same thing. A model can decrease its loss while accuracy stays flat, especially when the model is becoming more calibrated in its probability estimates without changing its top prediction. Conversely, a small change in loss near a decision boundary can flip predictions and cause a large jump in accuracy. This disconnect is why you should always monitor both during training. In specialized domains, you may even design custom loss functions — for instance, weighting false negatives more heavily than false positives in medical diagnosis — because the standard losses treat all errors equally, and your problem may not.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Dividing Integers → Unit Rates → Proportions → Percent Concept → Converting Between Fractions, Decimals, and Percents → Operations with Rational Numbers → Two-Step Equations → Solving Multi-Step Equations → Equations with Variables on Both Sides → Angle Pairs: Complementary, Supplementary, and Vertical → Parallel Lines and Transversals → Corresponding Angles → Alternate Interior Angles → Triangle Angle Sum Theorem → Exterior Angle Theorem → Triangle Inequality Theorem → Similar Triangles: AA Similarity → Similar Triangles: SSS and SAS Similarity → Proportions in Similar Triangles → Right Triangle Trigonometry Introduction → Sine, Cosine, and Tangent Ratios → Trigonometric Ratios Review → Radian Measure → Converting Between Degrees and Radians → The Unit Circle → Graphing Sine and Cosine → Graphing Tangent and Reciprocal Trigonometric Functions → Derivatives of Trigonometric Functions → Antiderivatives → Indefinite Integrals → Basic Integration Rules → Riemann Sums → Definite Integral Definition → Probability Density Functions and Continuous Distributions → Cumulative Distribution Functions → Continuous Random Variables → Probability Density Functions → Expected Value → Linear Regression in Machine Learning → Neural Network Fundamentals → Backpropagation Algorithm → Multilayer Perceptrons (MLPs) → Activation Functions in Neural Networks → Vanishing Gradient Problem → Gradient Descent and Optimization → Loss Functions and Objective Functions

Longest path: 98 steps · 674 total prerequisite topics

Prerequisites (4)

Leads To (1)