An objective function is the value a model optimizes during training. Learn how it differs from loss and cost functions, common examples, and how to choose one.

Updated August 2026
A model optimizes exactly one number, and it does not care whether that number is the right one. That number is the objective function, and choosing it badly is how you end up with a model that is technically optimized and practically useless.
Quick answer: An objective function is the function a model optimizes during training. An optimizer adjusts the model's parameters to make its value as low, or as high, as the goal requires. Loss functions and cost functions are objective functions the model minimizes. Mean squared error and cross-entropy are common examples.
The objective function is the one number a whole training run works to move. The data you feed the model, the architecture you choose, and the learning rate you set all exist to push it in the right direction.
It is the model's only measure of success. A model does not chase accuracy or usefulness directly; it chases the objective, and nothing else. Whatever moves that single value is exactly what the model learns to do.
The three terms overlap, and the difference is mostly scope. Google's machine learning glossary defines loss as a measure of how far a model's prediction sits from the label.
| Term | Scope | Direction |
|---|---|---|
| Loss function | One example | Minimize |
| Cost function | Whole dataset, often plus regularization | Minimize |
| Objective function | Anything the optimizer targets | Minimize or maximize |
In day-to-day use, people say "loss" and "objective" almost interchangeably during training. The distinction earns its keep when a task maximizes something, such as a reward or a likelihood, where "loss" would be the wrong word.
The right objective function depends on the task.
PyTorch ships these as ready-made loss functions, so the work is less about writing the formula and more about matching it to the task and to the errors you can least afford.
For a sense of the numbers, take mean squared error. A model predicting [2.0, 3.0] against targets [2.5, 2.0] scores ((2.0 - 2.5)² + (3.0 - 2.0)²) / 2 = (0.25 + 1.0) / 2 = 0.625. Training lowers that value by adjusting the model until its predictions sit closer to the targets, and a perfect fit would drive it to zero.
A model optimizes its objective function through gradient descent. The optimizer measures how the objective changes as each parameter changes, then nudges every parameter a small step in the direction that improves it. Repeat over many batches, and the value settles toward a minimum, or a maximum.
The size of each step is the learning rate. Too large and the value bounces without settling; too small and training crawls. The objective function defines the landscape, and gradient descent is how the model walks it.

No, the two are not the same. An objective function is what the model optimizes during training; an evaluation metric is how you judge the finished model. They are often different on purpose. A classifier can minimize cross-entropy during training while you score it on the F1 score, because F1 reflects the precision-and-recall tradeoff you actually care about.
The reason for the split is practical. Many useful metrics, such as accuracy or F1, are not smooth enough to optimize directly with gradient descent, so training uses a smooth stand-in like cross-entropy and keeps the real metric for evaluation.
The objective function encodes what "good" means to the model, and the model takes it literally. Optimize a recommender for watch time, and it learns to maximize watch time, even by promoting content that keeps people scrolling past the point they enjoy it. The model did its job; the objective described the wrong goal.
This is why the objective deserves more scrutiny than the architecture. A stronger model optimizing the wrong objective is a faster route to the wrong outcome. Before tuning anything, write down the real goal and confirm that lowering the loss actually moves it.
Yes, in two common ways. A regularized objective adds a penalty to the main loss, such as a term that discourages large weights, so the model works to reduce error and complexity together. A multi-task model optimizes several objectives at once, each with a weight that sets its priority.
Those weights become their own decision. Set the regularization weight too high and the model underfits; too low and it overfits. Balancing several objectives is less about the formulas than about deciding which outcome wins when two of them pull in different directions.
Either works, depending on how the objective is defined. Loss and cost functions are built to be minimized, where lower is better. Reward functions and likelihoods are built to be maximized, where higher is better. The two are interchangeable, because maximizing a value is the same as minimizing its negative, which is why some frameworks express everything as a minimization.
What matters is that the direction matches the goal. An objective pointed the wrong way, or one that rewards the wrong behavior, produces a model that optimizes confidently toward the wrong result.

You choose an objective function by matching it to the task type and the cost of each error. Regression usually points to squared or absolute error, classification to cross-entropy, and ranking or probabilistic tasks to their own likelihood-based objectives. The framework supplies the formula; the judgment is the match.
Then check the objective against the outcome you are paid to move. If the loss can fall while the real metric stalls, the objective and the goal have drifted apart. See the machine learning framework overview for where the objective sits in the wider training pipeline.
An objective function is the value a model optimizes during training. An optimizer adjusts the model's parameters to make it as low or as high as the goal requires. Loss and cost functions are objective functions the model minimizes.
Yes, a loss function is an objective function that measures error and is minimized. "Objective function" is the broader term, covering both minimized losses and maximized objectives such as reward or likelihood.
A cost function is usually the average loss over the whole training set, often with a regularization term. An objective function is the general term for whatever the optimizer targets, which includes cost functions and cases where the goal is maximization.
You can do either, depending on how the objective is defined. Loss and cost functions are minimized; reward functions and likelihoods are maximized. Maximizing a value is the same as minimizing its negative, so the two directions are interchangeable.
This content was generated with the assistance of AI. Our AI prompt chain workflow is carefully grounded and preferences .gov and .edu citations when available. All content is reviewed by a Telnyx employee to ensure accuracy, relevance, and a high standard of quality.