मुख्य सामग्री पर जाएँ

हानि फलन

हानि फलन तय करता है कि आप वास्तव में किसे दंडित करते हैं — इसे बदलिए, तो सही-गलत की धारणा ही बदल जाती है

02 मशीन लर्निंगमध्यवर्तीइस क्षेत्र की प्रविष्टि 3

यह पृष्ठ अंग्रेज़ी में प्रस्तुत है; शीर्षक और सारांश का स्थानीयकरण किया गया है।

परिभाषा

A loss function maps the gap between a prediction and the true label to a single non-negative number, and training simply tries to make its average as small as possible. Mean squared error penalises squared deviations and suits regression; cross-entropy penalises “assigning too little probability to the correct answer” and suits classification. Choosing a loss is declaring how much you are willing to pay for which kind of mistake.

सहज समझ

Think of a loss as a penalty rule. The same ten-minute lateness can be fined linearly per minute, or doubled the moment you are late — and each rule elicits completely different behaviour. A loss function is exactly that rule for a model: it decides which mistakes get corrected first and which get tolerated. Swap the loss and you swap the entire notion of right and wrong.

चित्र 1

The shape of two losses (binary classification, true label positive): cross-entropy rises sharply when wrong, while mean squared error stays too flat

  • Cross-entropy (true = positive)
  • Mean squared error
चित्र 2

Convergence of three losses on one classification task (schematic): cross-entropy descends fastest, mean squared error learns noticeably slower in the saturated regime

  • Cross-entropy
  • MSE (used for classification)
  • Hinge loss

कार्यप्रणाली

  1. 01

    Measure the per-sample error

    For each sample, quantify the gap between prediction and label. Regression uses squared difference; classification uses the negative log of the probability assigned to the correct class — how surprised you should be by the outcome.

  2. 02

    Average into a total loss

    Sum or average the per-sample errors into a single scalar over the training set. That scalar is what gradient descent actually minimises.

  3. 03

    Let the gradient drive correction

    Differentiate the loss to obtain the direction and magnitude for every parameter. Whether the loss is differentiable and its gradient smooth directly determines how stable optimisation will be.

  4. 04

    Pick the loss for the task

    Regression defaults to mean squared error, classification to cross-entropy; when margin matters or outliers are a concern, Hinge or contrastive losses come in. The criterion is always: which kind of mistake do you fear most?

मुख्य सूत्र

L_CE = − Σ_c y_c · log p̂_c
Cross-entropy loss: y is the one-hot label and p̂ the predicted class probabilities. The lower the probability assigned to the correct class, the larger the loss.

उपयोग के क्षेत्र

  • Regression: house prices, temperature and coordinates trained with mean squared error and its variants
  • Classification: image and text classifiers almost universally use cross-entropy
  • Metric learning: contrastive and triplet losses pull similar samples together and push dissimilar ones apart
  • Class imbalance: weighted cross-entropy or Focal Loss keep the model from fixating on the majority class

सामान्य भ्रांतियाँ

  • Mean squared error paired with a Sigmoid vanishes. In classification, MSE on a saturating Sigmoid output yields gradients so small the weights barely move — exactly why cross-entropy wins in classification.
  • Falling loss does not mean a better metric. While training loss keeps dropping, the accuracy or recall you care about may stall or decline, because the loss optimises a proxy rather than the end goal.
  • Sensitivity to outliers varies by loss. Mean squared error is dominated by extreme values; mean absolute error or Huber is more robust, at the cost of non-differentiability or a kink near zero.

मुख्य शब्द

Mean squared error (MSE)
The average squared difference between prediction and label; the default regression loss
Cross-entropy
Negative log-probability of the correct class; the default classification loss
Hinge loss
Requires the correct class to win by a margin; the heart of the SVM
Contrastive loss
A loss that pulls same-class embeddings together and pushes different-class ones apart

आगे का पठन