Minkowski distance

Minkowski distance is a distance measured between two points in N-dimensional space. It is basically a generalization of the Euclidean distance and the Manhattan distance. It is widely used in the field of Machine learning, especially in the concept to find the optimal correlation or classification of data. Minkowski distance is used in certain algorithms also like K-Nearest Neighbors, Learning Vector Quantization (LVQ), Self-Organizing Map (SOM), and K-Means Clustering.

Let us consider a 2-dimensional space having three points P1 (X1, Y1), P2 (X2, Y2), and P3 (X3, Y3), the Minkowski distance is given by ( |X1 – Y1|p + |X2 – Y2|p  + |X2 – Y2|p )1/p. In R, Minkowski distance is calculated with respect to vectors.

For example,

we are given two vectors, vect1 as (4, 2, 6, 8) and vect2 as (5, 1, 7, 9). Their Minkowski distance for p = 2 is given by, ( |4 – 5|2 + |2 – 1|2 + |6 – 7|2 + |8 – 9|2 )1/2  which is equal to 2. This article focuses upon how we can calculate Minkowski distance in R.

How to Calculate Minkowski Distance in R?

In this article, we are going to see how to calculate Minkowski Distance in the R Programming language.

Similar Reads

Minkowski distance:

Minkowski distance is a distance measured between two points in N-dimensional space. It is basically a generalization of the Euclidean distance and the Manhattan distance. It is widely used in the field of Machine learning, especially in the concept to find the optimal correlation or classification of data. Minkowski distance is used in certain algorithms also like K-Nearest Neighbors, Learning Vector Quantization (LVQ), Self-Organizing Map (SOM), and K-Means Clustering....

Method 1:Using a custom function

We can calculate Minkowski distance between a pair of vectors by apply the formula,...

Method 2: Using inbuilt dist() function

...