AI Glossary / Mathematics and optimization / Intermediate

Minkowski distance

Definition

Minkowski distance is a family of distances between numerical vectors, defined for p≥1 by d_p(x,y)=(sum_i |x_i−y_i|^p)^(1/p). The parameter p determines how coordinate differences are combined. Manhattan distance is the p=1 case, and Euclidean distance is the p=2 case.

What it means

The same pair of points can have different numerical distances depending on p. More importantly, changing p can change which of several candidates is nearest to a query. The parameter is therefore part of the model's notion of similarity, not just a different display format.

For finite-dimensional vectors, letting p increase without bound gives the largest absolute coordinate difference, often called Chebyshev or max-norm distance. For 0<p<1, the same algebraic expression can be calculated, but it generally fails the triangle inequality and is not an ordinary metric. This entry uses the metric family p≥1.

How it works

Subtract corresponding coordinates, take absolute values, raise them to the power p, sum, and take the pth root. Every coordinate participates unless a separate weighting convention excludes it.

For p≥1, the result is nonnegative, symmetric, zero only for identical vectors, and satisfies the triangle inequality. These properties make it a metric and support algorithms that rely on metric geometry.

Weighted versions use a sum of w_i|x_i−y_i|^p. Strictly positive finite weights preserve a metric on the full coordinate space; zero weights can make different vectors have distance zero if they differ only in ignored coordinates. Feature scaling and weighting are closely related, so their meaning needs attention. A distance computation cannot decide whether comparing a salary coordinate with a temperature coordinate is substantively sensible.

Three practical examples

1. Nearest-neighbor prediction: choose a distance that reflects how differences across numerical features should combine when selecting nearby examples.

2. Similarity retrieval: rank candidate records by their distance from a query after appropriate feature preparation and scaling.

3. Error comparison: distinguish total absolute discrepancy, Euclidean discrepancy, and the largest component discrepancy using p=1, p=2, and the limiting max-distance case.

Think of it this way

Think of traveling between two points on a map. Manhattan distance counts movement along perpendicular streets, while Euclidean distance measures a straight line. Max distance records the larger coordinate change when simultaneous coordinate progress is the relevant abstraction.

The analogy does not define the right metric for arbitrary data. Real roads can have obstacles, and feature coordinates need not represent physical directions. A useful data distance depends on the meaning and scaling of those coordinates.

Worked example

Take x=(1,2) and y=(4,6). Their absolute coordinate differences are 3 and 4. For p=1, the distance is 3+4=7. For p=2, it is √(3²+4²)=5. For p=3, it is the cube root of 27+64, or the cube root of 91, approximately 4.498. In the limiting max-distance case, it is 4.

Now compare two candidates with the origin: A=(3,0) and B=(2,2). Under p=1, A has distance 3 and B has distance 4, so A is nearer. Under p=2, A still has distance 3, while B has distance √8, approximately 2.828, so B is nearer. Changing p changes the neighbor ranking.

To see why the restriction matters, use p=0.5 with points O=(0,0), U=(1,0), and V=(1,1). The expression gives distance 4 from O to V, but distances 1 from O to U and 1 from U to V. Thus 4 is greater than 1+1, violating the triangle inequality. This is not the metric family assumed by algorithms that require that property.

Illustrative case study

Fictional case: a recommendation team compares products using price and a quality rating. The raw price values dominate distances because their numerical range is much larger than the rating scale.

The team reviews feature transformations and scaling before tuning p. It then evaluates whether nearest neighbors are useful on held-out recommendation cases and checks sensitivity to different defensible choices. The exercise prevents the team from mistaking an arbitrary unit convention for a meaningful preference. No single Minkowski parameter automatically solves that modeling problem.

Common misconceptions and mistakes

Do not confuse changing p with rescaling features: both affect geometry, but in different ways. Do not assume that all choices preserve the same nearest neighbors.

For p below one, the expression generally loses the triangle inequality. With weighted distances, a zero weight can erase distinctions between different points. Also avoid assuming that a smaller numerical distance after changing p proves improved similarity; distances from different definitions are not interchangeable quality scores. The application must validate the resulting relationships.

Business use

Minkowski distances offer a simple, explicit way to define similarity across numeric attributes. Their transparency can help teams explain why certain records are considered neighbors and why feature preparation changes those neighbors.

For a business application, document p, feature transformations, units, and weights. Compare outcomes on representative cases rather than choosing a metric solely because it is familiar. If an indexing or search algorithm assumes a true metric, ensure the selected distance and weighting meet those assumptions before relying on its behavior.

People also ask

Is Euclidean distance a Minkowski distance?

Yes. It is the p=2 member of the family.

What happens as p approaches infinity?

For finite vectors, the distance approaches the largest absolute coordinate difference.

Can p be less than one?

The expression can be computed, but it generally is not a metric because the triangle inequality fails.

Check your understanding

Two vectors differ in absolute value by (2,2,1). What are their p=1 and p=2 distances?

Answer: The p=1 distance is 5. The p=2 distance is √(4+4+1)=3. Both describe the same differences under different aggregation rules.

Related terms

  • Metric
  • Norm
  • Manhattan distance
  • Euclidean distance
  • Nearest neighbor
  • Chebyshev distance
  • feature scaling
  • nearest neighbors
  • weighted distance

Learn next

draw equal-distance contours for p=1, p=2, and the max-distance limit. Then test how p and feature scaling separately change nearest-neighbor rankings, keeping the triangle-inequality requirement in view.

  • Nearest neighbor
  • Triangle inequality

More in Mathematics and optimization

  • Absolute error loss - Absolute error loss measures a numerical prediction's error as the absolute difference between its predicted and reference values: L(y,y-hat)=|y-y-hat|.
  • Active-set method - An active-set method is an optimization approach that works with a changing subset of constraints believed to be tight at the solution.
  • Adjoint state method - The adjoint state method computes how a chosen objective changes when the parameters of a mathematical model change.
  • Σ-algebra
  • Algebraic connectivity - Algebraic connectivity is the second-smallest eigenvalue of a graph's Laplacian matrix.
  • Algorithm IMED - Algorithm IMED, short for Indexed Minimum Empirical Divergence, is a method for choosing actions in a stochastic multi-armed bandit problem.

Sources

SciPy, Minkowski distance definition, weights, and the p<1 caveat: https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.minkowski.html . The primary documentation was read. The distance comparison, neighbor-ranking reversal, and triangle-inequality counterexample are original hand calculations.

Previous: Minimum spanning tree Next: Minority class

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer