Start writing here...
Absolutely! Loss functions are at the heart of training machine learning models—they tell the model how wrong its predictions are, so it can adjust and improve.
🧮 What is a Loss Function?
A loss function measures the difference between the model’s predicted output and the actual target (ground truth). The goal during training is to minimize this loss.
📌 Common Loss Functions:
🔷 1. Mean Squared Error (MSE)
- Used For: Regression problems
- Formula: MSE=1n∑i=1n(yi−y^i)2\text{MSE} = \frac{1}{n} \sum_{i=1}^{n}(y_i - \hat{y}_i)^2
- Meaning: Penalizes larger errors more heavily.
- Example: Predicting house prices.
🔶 2. Mean Absolute Error (MAE)
- Used For: Regression
- Formula: MAE=1n∑i=1n∣yi−y^i∣\text{MAE} = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i|
- Less sensitive to outliers than MSE.
🔸 3. Binary Cross-Entropy (Log Loss)
- Used For: Binary classification
- Formula: BCE=−1n∑i=1n[yilog(y^i)+(1−yi)log(1−y^i)]\text{BCE} = -\frac{1}{n} \sum_{i=1}^{n} \left[y_i \log(\hat{y}_i) + (1 - y_i) \log(1 - \hat{y}_i)\right]
- Meaning: Measures how close predicted probabilities are to actual labels.
🔹 4. Categorical Cross-Entropy
- Used For: Multi-class classification
- Same idea as binary cross-entropy, but generalized for multiple classes.
🟩 5. Hinge Loss
- Used For: Support Vector Machines (SVMs)
- Encourages correct classification with a margin of confidence.
⚠️ Choosing the Right Loss:
Problem Type | Loss Function |
---|---|
Regression | MSE, MAE, Huber Loss |
Binary Classification | Binary Cross-Entropy |
Multi-Class Classification | Categorical Cross-Entropy |
SVM | Hinge Loss |
Would you like visual graphs of how MSE and Cross-Entropy behave with different predictions?