Loss Functions
Loss Functions
UNIT – 1
Mean squared error (MSE) loss function is the sum of squared differences
between the entries in the prediction vector y and the ground truth vector
y_hat.
The mean squared error loss function is the perfect loss function if you're
dealing with a regression problem. That is, if you want your neural network
to predict a continuous scalar value.
An example of a regression problem would be predictions of . . .
a stock value.
Regression is only one of two areas where feedforward networks enjoy great
popularity. The other area is classification.
One important thing we need to discuss before continuing with the cross-
entropy is what exactly the ground truth vector looks like in the case of a
classification problem.
One-hot-encoded vector (left) and prediction
vector (right).
The label vector y_hat is one hot encoded which means the values in this
vector can only take discrete values of either zero or one. The entries in this
vector represent different classes. The values of these entries are zero,
except for a single entry which is one. This entry tells us the class into
which we want to classify the input feature vector x.
The prediction y, however, can take continuous values between zero and
one.
Given the prediction vector y and the ground truth vector y_hat you can
compute the cross-entropy loss between those two vectors as follows:
We can see clearly that the cross-entropy loss function grows exponentially
for lower values of the predicted probability y_i. For y_i=0 the function
becomes infinite, while for y_i=1 the neural network makes an accurate
probability prediction and the loss value goes to zero.
In the travel and tourism industry, we can use demand forecasting models
to assess optimal price points for flights and hotels, in light of available
capacity, what price should be assigned (for hotels, flights), which
destinations should be spotlighted, or, what types of packages should be
advertised.
Why is that?
Well, imagine the MSE loss function gives you a value of 100. Can you tell if
this is generally a good result? No, because it depends on the situation. If
the prediction y of the model is 1000 and the actual ground truth label
y_hat is 1010, then the MSE loss of 100 would be in fact a very small error
and the performance of the model would be quite good.
However in the case where the prediction would be five and the label is 15,
you would have the same loss value of 100 but the relative deviation to the
ground-truth value would be much higher than in the previous case.
This example shows the shortcoming of the mean squared error function as
the loss function for the demand forecasting models. For this reason, I
strongly recommend using mean absolute percentage error (MAPE).
In this equation, y_i is the predicted value and y_hat is the label. We divide
the difference between y_i and y_hat by the actual value y_hat again.
Finally, multiplying by 100 percent gives us the percentage error.
Applying this equation to the example above gives you a more meaningful
understanding of the model’s performance. In the first case, the deviation
from the ground truth label would be only one percent, while in the second
case the deviation would be 66 percent:
Reference:
https://builtin.com/machine-learning/loss-functions