liveBook · Manning

Manhattan distance

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

Manhattan distance is the sum of the absolute coordinate differences between two points.

Manhattan distance measures how far two points are by adding the absolute differences of their coordinates. For Tokyo property data, it can turn proximity to the Imperial Palace into a machine-learning feature. section 7.1.3

Unlike Euclidean distance, which assumes a straight-line path, Manhattan distance reflects horizontal and vertical movement through a city. It is also called city block distance, taxicab distance, or the L1 norm. section 7.1.3

Choose the distance measure according to the movement or geometry represented by the feature:

  • Use Manhattan distance when street layouts and road networks make horizontal and vertical travel more realistic. section 7.1.3
  • Use Euclidean distance when direct physical distance between locations is the more appropriate interpretation. section 7.1.3

Tokyo property proximity

A geographical feature compares each Airbnb accommodation with the Imperial Palace by summing absolute latitude and longitude differences, converting the result to meters, and storing it as imperial_palace_distance. The closest displayed listing has a distance of 137.394271 meters. section 7.1.3

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

How deep it goes
Defines the metric, contrasts it with Euclidean distance, and applies it to coordinates and nearest-neighbor queries.
Examples
Uses Tokyo Airbnb coordinates, the Imperial Palace, and nearby transportation and facility categories.
What it assumes
Assumes latitude-longitude coordinates and basic feature-engineering context while defining the metric in plain language.
What you can do after
Apply it via scikit-learn KDTree and coordinate transformations to create proximity features.
How it connects
Connects Manhattan distance with Euclidean distance, L1 norm, L2 norm, feature engineering, and KDTree.

Also explained in

Compare how 4 books explain Manhattan 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.