Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between loss function and metric in Keras? [duplicate]

It is not clear for me the difference between loss function and metrics in Keras. The documentation was not helpful for me.

like image 861
Zaratruta Avatar asked Jan 16 '18 12:01

Zaratruta


People also ask

Can we use metric as loss function?

The loss function is the function your algorithm tries to minimize and the metric is what you evaluate your model on. You will always need a metric to evaluate your model but particular algorithms will rely on a separate loss function during training, often as a proxy.

What is the loss function in keras?

The purpose of loss functions is to compute the quantity that a model should seek to minimize during training.

What is the difference between error function and loss function?

Loss function is sometimes also referred as Cost function. Loss Function is an error in 1 data point while Cost Error Function is sum of all errors in a batch of dataset. MSE measures the average of the sum of squares of the errors. It averages squared difference between the estimated values and the actual value.

Is loss function same as accuracy?

By definition, Accuracy score is the number of correct predictions obtained. Loss values are the values indicating the difference from the desired target state(s).


3 Answers

The loss function is used to optimize your model. This is the function that will get minimized by the optimizer.

A metric is used to judge the performance of your model. This is only for you to look at and has nothing to do with the optimization process.

like image 148
sietschie Avatar answered Sep 22 '22 07:09

sietschie


The loss function is that parameter one passes to Keras model.compile which is actually optimized while training the model . This loss function is generally minimized by the model.

Unlike the loss function , the metric is another list of parameters passed to Keras model.compile which is actually used for judging the performance of the model.

For example : In classification problems, we want to minimize the cross-entropy loss, while also want to assess the model performance with the AUC. In this case, cross-entropy is the loss function and AUC is the metric. Metric is the model performance parameter that one can see while the model is judging itself on the validation set after each epoch of training. It is important to note that the metric is important for few Keras callbacks like EarlyStopping when one wants to stop training the model in case the metric isn't improving for a certaining no. of epochs.

like image 36
Pranay Mukherjee Avatar answered Sep 23 '22 07:09

Pranay Mukherjee


I have a contrived example in mind: Let's think about linear regression on a 2D-plane. In this case, loss function would be the mean squared error, the fitted line would minimize this error.

However, for some reason we are very very interested in the area under the curve from 0 to 1 of our fitted line, and thus this can be one of the metrics. And we monitor this metric while the model minimizes the mean squared error loss function.

like image 25
Sida Zhou Avatar answered Sep 21 '22 07:09

Sida Zhou