Hands-On Guide To Loss Functions Used To Evaluate A ML Algorithm – Analytics India Magazine

The loss function is a method of evaluating how well the algorithm performs on your dataset, most of the people are confused about the difference between loss function and the cost function. We will use the term cost function for a single training example and loss function for the entire training dataset. We always try to reduce the loss function of the models using optimization techniques like Gradient Descent.

Loss functions are categorized into two types of losses

So how to choose which loss function to use.? It depends on the output tensor of the model. In regression problems, the output tensor is continuous data, and the output tensor of classification problems are probability values. Depending on the output variable we need to choose loss function to our model. Sometimes while building optimization models we may use multiple loss functions depending on the output tensor.

In this article, we will discuss the following loss functions.

Based on the demonstrated implementations, we can use these loss functions to evaluate the accuracy of any machine learning algorithm.

MSE loss is popularly used loss functions in dealing with regression problems. MSE loss function is an estimator measuring the average of error squares, mathematically it calculates the squared differences between the actual value and the predicted value, it is very easy to understand and implement.

A large MSE value indicates a wider spread of data and a smaller MSE indicated the value is nearest to the mean.

Implementation in python

MAE loss is also categorized in the regression problem, MAE loss calculates the average of absolute differences between the actual value and predicted values, when our data includes outliers we use MAE, so what are outliers.? The data points that are too large or too small than the mean. By using MAE loss the outliers dont affect the model.

Cross entropy is mostly used loss function in dealing with classification problems, cross-entropy measures the classification model whose probability in the range of 0 to 1, cross-entropy loss nearer to 0 results low loss and loss nearer to 1 results high loss. We calculate the individual loss for each class in a multiclass classification problem. When the output is probability distribution we use cross-entropy which uses softmax activation in the output layer.

Home Hands-On Guide To Loss Functions Used To Evaluate A ML Algorithm

The above formula is similar to the likelihood function if y=o then y(log(p)) will be 0 if y=1 then (1-y)log(1-p) will be zero.

We use Cross entropy loss in Multi-class classification problems like object detection. Lets consider the ImageNet dataset in which we have 1000 classes to find the loss.

The hinge loss function is used for a binary classification problem, a loss function is used to evaluate how well the given boundary is separating the given data, hinge loss is mostly used in SVM, this is used in the combination of the activation function in the last layer. We use Hinge loss to classify whether an email is a spam or not.

In the above demonstration, we discussed various types of the loss function and saw that depending on the output tensor we need to choose the loss function. Choosing the loss function for our model is very important because using the loss function we evaluate our model and it helps in optimizing the model to obtain error and reaching the global minima. Based on the implementations we showed above, these loss functions can be used to evaluate the accuracy of any machine learning algorithm.

comments

Visit link:
Hands-On Guide To Loss Functions Used To Evaluate A ML Algorithm - Analytics India Magazine

Related Posts
This entry was posted in $1$s. Bookmark the permalink.