Neeharika Patel
Pythonโ€™s Gurus
2 min readJun 15, 2024

--

โœจ ๐…๐ซ๐จ๐ฆ ๐„๐ซ๐ซ๐จ๐ซ ๐ญ๐จ ๐„๐ฑ๐œ๐ž๐ฅ๐ฅ๐ž๐ง๐œ๐ž โœจ
๐‡๐จ๐ฐ ๐‹๐จ๐ฌ๐ฌ ๐…๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง๐ฌ ๐’๐ก๐š๐ฉ๐ž ๐๐ž๐ฎ๐ซ๐š๐ฅ ๐๐ž๐ญ๐ฐ๐จ๐ซ๐ค ๐“๐ซ๐š๐ข๐ง๐ข๐ง๐  โš›

โ™ป ๐–๐ก๐š๐ญ ๐ข๐ฌ ๐š ๐‹๐จ๐ฌ๐ฌ ๐…๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง?
Imagine youโ€™re teaching a child to throw a ball into a basket. Each time the child throws the ball, you can see how far off the throw was from hitting the target. A loss function is like that measurement โ€” it tells you how far off the neural networkโ€™s predictions are from the actual answers.

โ™ป ๐–๐ก๐ฒ ๐ƒ๐จ ๐–๐ž ๐๐ž๐ž๐ ๐š ๐‹๐จ๐ฌ๐ฌ ๐…๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง?
In the world of neural networks, we want our models to make accurate predictions. To achieve this, we need a way to measure how good or bad the modelโ€™s predictions are. This is where the loss function comes in. It provides a numerical value indicating the modelโ€™s prediction error.

โ™ป ๐‡๐จ๐ฐ ๐ƒ๐จ๐ž๐ฌ ๐ˆ๐ญ ๐–๐จ๐ซ๐ค?

1. ๐Œ๐š๐ค๐ž ๐š ๐๐ซ๐ž๐๐ข๐œ๐ญ๐ข๐จ๐ง: The neural network takes in some input data and makes a prediction.
2. ๐‚๐š๐ฅ๐œ๐ฎ๐ฅ๐š๐ญ๐ž ๐ญ๐ก๐ž ๐‹๐จ๐ฌ๐ฌ: The loss function compares the modelโ€™s prediction to the actual answer and calculates a loss value.
3. ๐€๐๐ฃ๐ฎ๐ฌ๐ญ ๐ญ๐ก๐ž ๐Œ๐จ๐๐ž๐ฅ: The neural network uses this loss value to adjust its internal parameters (weights and biases) to improve future predictions. This adjustment process is called training.

โ™ป ๐“๐ฒ๐ฉ๐ž๐ฌ ๐จ๐Ÿ ๐‹๐จ๐ฌ๐ฌ ๐…๐ฎ๐ง๐œ๐ญ๐ข๐จ๐ง๐ฌ:

1) ๐‘๐ž๐ ๐ซ๐ž๐ฌ๐ฌ๐ข๐จ๐ง ๐๐ซ๐จ๐›๐ฅ๐ž๐ฆ๐ฌ:
โ€ข ๐Œ๐ž๐š๐ง ๐’๐ช๐ฎ๐š๐ซ๐ž๐ ๐„๐ซ๐ซ๐จ๐ซ (๐Œ๐’๐„): Measures the average squared difference between predicted and actual values, heavily penalizing larger errors.
โ€ข ๐Œ๐ž๐š๐ง ๐€๐›๐ฌ๐จ๐ฅ๐ฎ๐ญ๐ž ๐„๐ซ๐ซ๐จ๐ซ (๐Œ๐€๐„): Measures the average absolute difference between predicted and actual values, providing a more robust metric against outliers.

2) ๐๐ข๐ง๐š๐ซ๐ฒ ๐‚๐ฅ๐š๐ฌ๐ฌ๐ข๐Ÿ๐ข๐œ๐š๐ญ๐ข๐จ๐ง ๐๐ซ๐จ๐›๐ฅ๐ž๐ฆ๐ฌ:
โ€ข ๐๐ข๐ง๐š๐ซ๐ฒ ๐‚๐ซ๐จ๐ฌ๐ฌ ๐„๐ง๐ญ๐ซ๐จ๐ฉ๐ฒ: Evaluates the difference between the predicted probability and the actual binary class label, penalizing incorrect predictions based on their confidence.

3) ๐Œ๐ฎ๐ฅ๐ญ๐ข๐œ๐ฅ๐š๐ฌ๐ฌ ๐‚๐ฅ๐š๐ฌ๐ฌ๐ข๐Ÿ๐ข๐œ๐š๐ญ๐ข๐จ๐ง ๐๐ซ๐จ๐›๐ฅ๐ž๐ฆ๐ฌ:
โ€ข ๐‚๐š๐ญ๐ž๐ ๐จ๐ซ๐ข๐œ๐š๐ฅ ๐‚๐ซ๐จ๐ฌ๐ฌ ๐„๐ง๐ญ๐ซ๐จ๐ฉ๐ฒ: Computes the difference between predicted probabilities and actual class labels for multiple classes, used when class labels are one-hot encoded.
โ€ข ๐’๐ฉ๐š๐ซ๐ฌ๐ž ๐‚๐š๐ญ๐ž๐ ๐จ๐ซ๐ข๐œ๐š๐ฅ ๐‚๐ซ๐จ๐ฌ๐ฌ ๐„๐ง๐ญ๐ซ๐จ๐ฉ๐ฒ: Similar to categorical cross entropy but used when class labels are provided as integers instead of one-hot encoded vectors.

#๐ƒ๐š๐ญ๐š๐€๐ง๐š๐ฅ๐ฒ๐ฌ๐ข๐ฌ #DataScience #๐ƒ๐š๐ญ๐š๐„๐ง๐ ๐ข๐ง๐ž๐ž๐ซ๐ข๐ง๐  #๐Œ๐š๐œ๐ก๐ข๐ง๐ž๐‹๐ž๐š๐ซ๐ง๐ข๐ง๐  #๐ƒ๐ž๐ž๐ฉ๐‹๐ž๐š๐ซ๐ง๐ข๐ง๐  #LossFunction #๐๐ž๐ฎ๐ซ๐š๐ฅ๐๐ž๐ญ๐ฐ๐จ๐ซ๐ค #๐ƒ๐ข๐ ๐ข๐ญ๐š๐ฅ๐๐ซ๐š๐ข๐ง #๐€๐ซ๐ญ๐ข๐Ÿ๐ข๐œ๐ข๐š๐ฅ๐ˆ๐ง๐ญ๐ž๐ฅ๐ฅ๐ข๐ ๐ž๐ง๐œ๐ž #๐†๐ž๐ง๐ž๐ซ๐š๐ญ๐ข๐ฏ๐ž๐€๐ˆ #๐๐ž๐ซ๐œ๐ž๐ฉ๐ญ๐ซ๐จ๐ง #๐Œ๐‹๐

Pythonโ€™s Gurus๐Ÿš€

Thank you for being a part of the Pythonโ€™s Gurus community!

Before you go:

  • Be sure to clap x50 time and follow the writer ๏ธ๐Ÿ‘๏ธ๏ธ
  • Follow us: Newsletter
  • Do you aspire to become a Guru too? Submit your best article or draft to reach our audience.

--

--