liveBook · Manning

Euclidean distance

As explained in Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

Euclidean distance is the straight-line distance between two points in Euclidean space.

Euclidean distance measures the straight-line distance between two points in Euclidean space. It assumes a direct path and can suit physical-distance features. section 7.1.3

When engineering geographical features, compare distance measures with the movement the feature should represent:

  • Choose Euclidean distance when direct physical separation matters. section 7.1.3
  • Choose Manhattan distance when city streets, road networks, and horizontal or vertical travel better reflect accessibility. section 7.1.3
  • Recognize Euclidean distance as closely related to the L2 norm; Manhattan distance similarly corresponds to the L1 norm. section 7.1.3

Tokyo accommodation features

For Airbnb listings near Tokyo’s Imperial Palace, convert coordinate differences into meters before inspecting distances. A nearest-listing result can then support a location feature, while city accessibility may favor Manhattan distance instead. section 7.1.3

Listing 7.5 Computing a distance metric from the city center
imperial_palace_lat = 35.6841822633
imperial_palace_lon = 139.751471994
 
def degrees_to_meters(distance_degrees, latitude):
    conversion_factor = 111000                              #1
    distance_meters = (distance_degrees * conversion_factor 
                       * np.cos(np.radians(latitude)))      #2
    return distance_meters 
 
distance_degrees = (
    np.abs(
        summary_listings['latitude'] 
        imperial_palace_lat) + 
    np.abs(
        summary_listings['longitude'] 
        imperial_palace_lon)
)                                                           #3
 
summary_listings['imperial_palace_distance'] = (
    degrees_to_meters(distance_degrees,
    summary_listings['latitude']
)

Inspect the coordinate-to-meters workflow used to create a distance feature from latitude and longitude. section 7.1.3

How Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI covers it

How deep it goes
Defines direct-path distance, relates it to the L2 norm, and stops short of a dense mathematical derivation.
Examples
Uses Tokyo Airbnb listings, Imperial Palace coordinates, meter conversion, and nearest-location inspection.
What it assumes
Assumes latitude, longitude, and basic machine-learning feature-engineering context.
What you can do after
Evaluate whether straight-line or Manhattan distance better represents a geographical machine-learning feature.
How it connects
Connects Euclidean distance with Manhattan distance, L2 norms, coordinates, and geographical feature engineering.

Also explained in

Compare how 8 books explain Euclidean distance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI. The section links point to the parts of the book it draws on.