0

Good morning guys,

I would like to calculate the RMSE error between two gps coordinates (latitude and longitude).

Do you know if and how I can apply it to a known coordinate pair?

gcicceri
  • 33
  • 3
  • Can you add a little bit more detail about your problem ? You want to calculate RMSE between 2 type of latitude/longitude ? Example: RMSE between predicted latitude and ground truth latitude ? – Yohann L. Jul 22 '22 at 17:57
  • Yes, exactly. I have GROUND TRUTH of pair Lat and Long for example (37.537008 , 15.069104) and my prediction (37.536948 , 15.069109). The goal is to calculate RMSE error between these gps coordinates (also in terms of meters). Thanks a lot in advance – gcicceri Jul 23 '22 at 19:11

1 Answers1

0

RMSE of latitude/longitude:

Using numpy you can do the following for longitude, and same for the latitude.

import numpy as np
longitude = [1,2,3,4,5]
longitude_pred = [1.6,2.5,2.9,3,4.1]
 
MSE_longitude = np.square(np.subtract(longitude, longitude_pred)).mean() 
 
RMSE_longitude = np.sqrt(MSE)

If your coordinates is matrix of shape [2, n]:

import numpy as np
long_lat = [[1,2,3,4,5], [1,2,3,4,5]]
long_lat_pred = [[1.6,2.5,2.9,3,4.1], [1.6,2.5,2.9,3,4.1]]
 
MSE_long_lat = np.square(np.subtract(long_lat, long_lat_pred)).mean(axis=1)
 
RMSE_long_lat = np.sqrt(MSE)

Distance between coordinates in meters:

To get a value in meters, you can for example calculate the distance between each points ((long, lat), (long_pred, lat_pred)) in meter using the Haversine formula. (More info on Getting distance between two points based on latitude/longitude) But you can't get the RMSE in meters I think.

For one set of coordinates and predictions you can calculates the distance using geopy:

import geopy.distance

coords_1 = (52.2296756, 21.0122287)
coords_2 = (52.406374, 16.9251681)

print(geopy.distance.geodesic(coords_1, coords_2).km)

>>> 279.352901604

Then for a set of coordinates:

coords_1 = np.array([[52.2296756, 21.0122287], [53.2296756, 22.0122287]])
coords_2 = np.array([[52.406374, 16.9251681], [51.406374, 18.9251681]])

distance_in_meters = [geodesic(coord1, coord2).km for coord1, coord2 in zip(coords_1, coords_2)]

print(distance_in_meters)

>>> [279.35290160430094, 292.3121626267748]
Yohann L.
  • 1,262
  • 13
  • 27