3
$\begingroup$

I'm searching for a loss function that fits my Project. Actually I have two question but they are in the same direction. I take a look at the definition of the root mean squared error and the euclidean distance and they look the same to me! that's why I want to know what's the difference between the two. what would be the difference if I use rmse as a loss function or the euclidean distance??

the second question is how to search for a loss function. I mean I know it depends on the problem and commun things are MSE for Regression and Cross entropy for Classification but let's say I have a specific problem, how do I search for a loss function? I also saw that some people use a custom loss function and most of the deep learning frameworks allows us to define a custom loss function but why would I want to use a custom one? how I get the intuition that I need a custom loss function?

now to explain my problem. I'm doing a project where I need to reduce the GPS Error of a vehicle (I have some vehicle data and my neural network will try to predict the longitude and latitude so it's a regression problem) that's why I get the Idea of maybe the euclidean distance would make sense as a loss function, right? now somehow MSE also make sense to me because it is getting the difference between prediction and ground truth. does this make sense to you as a professional ML Engineer or Data scientist ? and if there would be a custom loss function that you can use, what would you suggest and why?

$\endgroup$

3 Answers 3

2
$\begingroup$

Euclidean distance simply refers to a metric of a specific type (a line between two points in a Euclidean space). Whereas RMSE is an error function for a specific purpose (the square root of the average squared distance between the actual score and the predicted score).

Where you may be getting confused is that RMSE is an example of a Euclidean distance between two regressions by averaging they specific vector errors over a whole regression, see here for a more in depth summary.

To summarise, RMSE is a type of Euclidean distance, but there are others.

The rest of your question of a specifc loss function for your problem, like you said, is very problem specific. I suggest posting a specific question with more details of your specific problem and solutions you've considered (need more details than above) to try and find a good loss function.

Hope that helps.

$\endgroup$
1
$\begingroup$

Let's say that RMSE and euclidean distance are not of the same type, even though their formulations are close. RMSE is a loss function, while euclidean distance is a metric. See this question on Cros Validated to better understand the difference between a loss function and a metric: a loss function is generally based on a reference metric.

Euclidean distance is a metric, so it quantifies the distance between two observations. RMSE is, as the name suggests, the root of the mean of the squared error between a true value and a predicted value, over a range of observations. RMSE is generally intended for model performance assessment.

Your confusion probably comes from the fact that, if you apply the RMSE formula to your set of coordinates (longitude and latitude), it gives the euclidean distance. But this would not be called RMSE in that case, rather euclidean distance.

In your case, you may use the RMSE of euclidean distance as loss function. The error made by your predictor is the euclidean distance, and your loss function would be the RMSE of these errors.

Defining a loss function is strongly problem-specific. First, you need to determine which metrics to use as error function. In your case, the euclidean distance between the actual position and the predicted one is an obvious metric, but it is not the only possible one. For instance, you could use the squared or cubed euclidean distance in order to give more weight to cases that are not well predicted. You could also design an ad-hoc metric to consider:

  • assymmetry, e.g. to be more tolerant on errors towards the east side than the west side
  • anisotropy, e.g. to be more tolerant on errors in the latitude axis than the longitude
  • uncertainty tolerance, e.g. error is null if the euclidean distance is less than a tolerance, and is equal to the euclidean distance otherwise
  • etc. (depending on your problem)

The subsequent metric will allow you to evaluate the performance of the trained model over a test set, and will therefore give you a disitrbution of errors. You need to shrink this distribution to a single scalar value used as global model performance: you can pretty much choose any scalar that represents something about the distribution:

  • Mean squared error (MSE) or its root (RMSE) - MSE is faster computed but RMSE has the advantage or having the same dimension as the error function (a distance in your case)
  • Other types of $\mathcal{L}_p$ norms (RMSE is the $\mathcal{L}_2$ norm)
  • Any quantile of the distribution (median, 75%, 95%, maximum value)
  • Whatever you think is relevant!
$\endgroup$
0
$\begingroup$

The earlier two answers are great and thorough so I won't repeat any of their info; another idea that may be helpful is the dimensionality of the two functions.

Firstly, an important detail: the Euclidian distance function is only the same as the RMSE when applying them to points in one dimension. In higher dimensions (or when using more than one instance for RMSE), Euclidian distance takes the sum whereas RMSE takes the average.

Now lets compare the dimensions that each function take.

The RMSE can only take one dimensional data, whereas Euclidian distance can take any number of dimensions. Both formulas sum the "error" (aka, the one dimentional distance between two points) but consider the difference between each error being summed:

  • With Euclidian distance, each "error" being summed is in a different dimension, and each error corresponds to comparing the same two points in a specific dimension. The result is a straight line between the two points.
  • With RMSE, each error being summed is in the same, single dimension (think the number line), and each error corresponds to comparing two values from different points.

An example to clarify:

  • Euclidian example: trivially, you have two points in 3D space. For each dimension, you find the difference in length between the points. Square, sum, and square root these three differences and the result is a straight line between the points.
  • RMSE example: your ML model takes in birth year and returns predicted age, and you use the model to predict the age of three people. The RMSE is simply finding, 3 times, the difference between the actual and predicted age, and then applying some more math (square, average, square root). It's in 1D space, and is the amplified (squared) average of three separate instances; the result is not a distance, but instead, simply one way of getting the average of multiple errors.

To drive this point even further, the RMSE for N-dimensional outputs is N separate RMSE values. In other words, even when there are multiple dimensions to work with, the RMSE is only applied to one dimension at a time.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.