Skip to content

Commit d23389a

Browse files
authored
Updated maths formulas
1 parent 56e9721 commit d23389a

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

contrib/machine-learning/Types_of_Cost_Functions.md

+23-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ MSE is one of the most commonly used cost functions, particularly in regression
1212

1313
**Mathematical Formulation:**
1414
The MSE is defined as:
15-
$$ MSE = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 $$
15+
$$MSE = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2$$
1616
Where:
1717
- \( n \) is the number of samples.
1818
- \( y_i \) is the actual value.
@@ -41,7 +41,7 @@ MAE is another commonly used cost function for regression tasks. It measures the
4141

4242
**Mathematical Formulation:**
4343
The MAE is defined as:
44-
$$ MAE = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i| $$
44+
$$MAE = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i|$$
4545
Where:
4646
- \( n \) is the number of samples.
4747
- \( y_i \) is the actual value.
@@ -70,8 +70,11 @@ def mean_absolute_error(y_true, y_pred):
7070
Cross-entropy loss is commonly used in binary classification problems. It measures the dissimilarity between the true and predicted probability distributions.
7171

7272
**Mathematical Formulation:**
73+
7374
For binary classification, the cross-entropy loss is defined as:
74-
$$ \text{Cross-Entropy} = -\frac{1}{n} \sum_{i=1}^{n} [y_i \log(\hat{y}_i) + (1 - y_i) \log(1 - \hat{y}_i)] $$
75+
76+
$$\text{Cross-Entropy} = -\frac{1}{n} \sum_{i=1}^{n} [y_i \log(\hat{y}_i) + (1 - y_i) \log(1 - \hat{y}_i)]$$
77+
7578
Where:
7679
- \( n \) is the number of samples.
7780
- \( y_i \) is the actual class label (0 or 1).
@@ -100,8 +103,11 @@ def binary_cross_entropy(y_true, y_pred):
100103
For multiclass classification problems, the cross-entropy loss is adapted to handle multiple classes.
101104

102105
**Mathematical Formulation:**
106+
103107
The multiclass cross-entropy loss is defined as:
104-
$$ \text{Cross-Entropy} = -\frac{1}{n} \sum_{i=1}^{n} \sum_{c=1}^{C} y_{i,c} \log(\hat{y}_{i,c}) $$
108+
109+
$$\text{Cross-Entropy} = -\frac{1}{n} \sum_{i=1}^{n} \sum_{c=1}^{C} y_{i,c} \log(\hat{y}_{i,c})$$
110+
105111
Where:
106112
- \( n \) is the number of samples.
107113
- \( C \) is the number of classes.
@@ -131,8 +137,11 @@ def categorical_cross_entropy(y_true, y_pred):
131137
Hinge loss is commonly used in support vector machines (SVMs) for binary classification tasks. It penalizes misclassifications by a linear margin.
132138

133139
**Mathematical Formulation:**
140+
134141
For binary classification, the hinge loss is defined as:
135-
$$ \text{Hinge Loss} = \frac{1}{n} \sum_{i=1}^{n} \max(0, 1 - y_i \cdot \hat{y}_i) $$
142+
143+
$$\text{Hinge Loss} = \frac{1}{n} \sum_{i=1}^{n} \max(0, 1 - y_i \cdot \hat{y}_i)$$
144+
136145
Where:
137146
- \( n \) is the number of samples.
138147
- \( y_i \) is the actual class label (-1 or 1).
@@ -165,17 +174,16 @@ Huber loss is a combination of MSE and MAE, providing a compromise between the t
165174
The Huber loss is defined as:
166175

167176

168-
$$
169-
\text{Huber Loss} = \frac{1}{n} \sum_{i=1}^{n} \left\{
177+
$$\text{Huber Loss} = \frac{1}{n} \sum_{i=1}^{n} \left\{
170178
\begin{array}{ll}
171179
\frac{1}{2} (y_i - \hat{y}_i)^2 & \text{if } |y_i - \hat{y}_i| \leq \delta \\
172180
\delta(|y_i - \hat{y}_i| - \frac{1}{2} \delta) & \text{otherwise}
173181
\end{array}
174-
\right.
175-
$$
182+
\right.$$
183+
176184
Where:
177185
- \( n \) is the number of samples.
178-
- \( \delta \) is a threshold parameter.
186+
- \(delta\) is a threshold parameter.
179187

180188
**Advantages:**
181189
- Provides a smooth loss function.
@@ -200,8 +208,11 @@ def huber_loss(y_true, y_pred, delta):
200208
Log-Cosh loss is a smooth approximation of the MAE and is less sensitive to outliers than MSE. It provides a smooth transition from quadratic for small errors to linear for large errors.
201209

202210
**Mathematical Formulation:**
211+
203212
The Log-Cosh loss is defined as:
204-
$$ \text{Log-Cosh Loss} = \frac{1}{n} \sum_{i=1}^{n} \log(\cosh(y_i - \hat{y}_i)) $$
213+
214+
$$\text{Log-Cosh Loss} = \frac{1}{n} \sum_{i=1}^{n} \log(\cosh(y_i - \hat{y}_i))$$
215+
205216
Where:
206217
- \( n \) is the number of samples.
207218

@@ -224,4 +235,4 @@ def logcosh_loss(y_true, y_pred):
224235

225236
These implementations provide various options for cost functions suitable for different machine learning tasks. Each function has its advantages and disadvantages, making them suitable for different scenarios and problem domains.
226237

227-
---
238+
---

0 commit comments

Comments
 (0)