A mathematical function that quantifies what a machine learning model is optimizing.
An objective function is a mathematical expression that defines the goal of an optimization problem by assigning a scalar value to any candidate solution or set of model parameters. In machine learning, it serves as the formal specification of what the algorithm is trying to achieve — whether that means minimizing prediction error, maximizing likelihood, or balancing competing objectives. Every training procedure implicitly or explicitly optimizes some objective function, making it one of the most foundational concepts in the field.
Objective functions generally fall into two categories based on the direction of optimization. Loss functions (also called cost functions) are minimized — common examples include mean squared error for regression, cross-entropy for classification, and hinge loss for support vector machines. Fitness or reward functions are maximized, as seen in evolutionary algorithms and reinforcement learning. In practice, the distinction is superficial since minimizing a function is equivalent to maximizing its negation, but the framing often reflects the problem domain and the algorithm's design.
The choice of objective function profoundly shapes model behavior. A poorly chosen objective can lead to models that technically minimize the stated criterion while failing at the actual task — a phenomenon sometimes called Goodhart's Law. For example, optimizing purely for accuracy on imbalanced datasets can produce models that ignore minority classes entirely. Regularization terms are frequently added to the primary objective to penalize model complexity, effectively turning the problem into a multi-term optimization that balances fit against generalization.
Modern deep learning has expanded the design space for objective functions considerably. Techniques like contrastive loss, triplet loss, and adversarial objectives (as in GANs) encode complex geometric or game-theoretic goals that go far beyond simple error minimization. The objective function also interacts tightly with the optimization algorithm used to minimize it — properties like convexity, smoothness, and the landscape of local minima all influence whether gradient descent or its variants will converge to useful solutions. Selecting and designing the right objective remains as much an art as a science.