Loss Function

A loss function measures how wrong a model's predictions are compared to the correct answers. Training works by adjusting the model to make this loss as small as possible.

Data & AI

The loss turns 'how far off were we?' into a single number the model can try to shrink. Smaller loss means better predictions. Different tasks use different losses — mean squared error for regression, cross-entropy for classification.

Think of it as the score in a game where lower is better. Gradient descent uses the loss to figure out which direction to nudge each parameter.

Examples

Python

import numpy as np

y_true = np.array([3.0, 5.0, 2.0])
y_pred = np.array([2.5, 5.0, 3.0])
mse = np.mean((y_true - y_pred) ** 2)
print(round(mse, 3))

Output:

0.417

Learn it in a lesson

See also

Back to the Dictionary