# What is Cost Function? Definition & Technical Mechanics

> **Source:** [SPIDITS AI AI Glossary](https://spidits.com/ai-glossary)  
> **Category:** Mathematical Foundations  
> **Canonical Citation:** [https://spidits.com/ai-glossary/cost-function](https://spidits.com/ai-glossary/cost-function)

## Definition
A Cost Function is a mathematical formula that measures the performance of a machine learning model on the entire dataset. It represents the average of the loss function values computed across all training examples.

## Architectural Mechanics & Deep Dive
A cost function (or loss function) is a mathematical formula that quantifies the error between a machine learning model's predictions and the actual ground-truth labels. The output of the cost function represents a penalty score. During training, optimization algorithms (like gradient descent) iteratively adjust the model's weights and biases to minimize this cost, driving the model toward higher accuracy and generalization.

## Industry Applications & Real-World Use Cases
Gradient optimization, learning model evaluation, and parameter updates.

## Frequently Asked Questions

### What is the difference between a loss function and a cost function?
A loss function measures error for a single training example. A cost function aggregates the errors across the entire dataset.

### How does optimization relate to the cost function?
Optimization algorithms (like gradient descent) iteratively adjust parameter weights to locate the global minimum of the cost function.

## Related Terminology
- [loss-function](https://spidits.com/ai-glossary/loss-function)
- [gradient-descent](https://spidits.com/ai-glossary/gradient-descent)
- [backpropagation](https://spidits.com/ai-glossary/backpropagation)

---
*From the SPIDITS AI Knowledge Base (336+ terms indexed). Explore full technical definitions: [https://spidits.com/ai-glossary](https://spidits.com/ai-glossary)*
