Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated distance_metrics.py #184

Merged
merged 2 commits into from
Oct 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 69 additions & 15 deletions MLlib/distance_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Distance_metrics:
Calculate distance between each corresponding points
of two arrays using different distance metrics
"""
def Eucledian_distance(self,X1,X2):
def Eucledian_Distance(X1,X2):
""""
Returns the list of eucledian distance
between two corresponding points of
Expand All @@ -18,13 +18,10 @@ def Eucledian_distance(self,X1,X2):
X2:ndarray(dtype=int,axis=1)
input array with more than 1 dimension

distance:list
list containing eucledian distance of points

RETURNS
=========

float
distance:list
Returns the list of eucledian distance
between two corresponding points of
two arrays
Expand All @@ -36,7 +33,7 @@ def Eucledian_distance(self,X1,X2):
distance.append(np.sqrt(single))
return(distance)

def Manhattan_distance(self,X1,X2):
def Manhattan_Distance(X1,X2):
""""
Returns the list of manhattan distance
between two corresponding points of
Expand All @@ -50,13 +47,10 @@ def Manhattan_distance(self,X1,X2):
X2:ndarray(dtype=int,axis=1)
input array with more than 1 dimension

distance:list
list containing manhattan distance of points

RETURNS
=========

float
distance:list
Returns the list of manhattan distance
between two corresponding points of
two arrays
Expand All @@ -68,7 +62,7 @@ def Manhattan_distance(self,X1,X2):
distance.append(single)
return(distance)

def Chebyshev_Distance(self,X1,X2):
def Chebyshev_Distance(X1,X2):
""""
Returns the list of chebyshev distance
between two corresponding points of
Expand All @@ -82,13 +76,10 @@ def Chebyshev_Distance(self,X1,X2):
X2:ndarray(dtype=int,axis=1)
input array with more than 1 dimension

distance:list
list containing chebyshev distance of points

RETURNS
=========

float
distance:list
Returns the list of chebyshev distance
between two corresponding points of
two arrays
Expand All @@ -100,7 +91,70 @@ def Chebyshev_Distance(self,X1,X2):
distance.append(single)
return(distance)

def Minkowski_Distance(X1,X2,p):
""""
Returns list of minkowski distance of order 'p'
between two corresponding vectors of
two arrays

PARAMETERS
==========
X1:ndarray(dtype=int,axis=1)
input array with more than 1 dimension

X2:ndarray(dtype=int,axis=1)
input array with more than 1 dimension

p:float
input order value between 1 and 2 inclusive

RETURNS
=========

distance:list
Returns the list of minkowski distance
between two corresponding vectors of
two arrays
"""
distance=[]
for i in range(len(X1)):
single=0
single=np.sum((abs(X1[i]-X2[i]))**p)
distance.append((single)**(1/p))
return(distance)

def WMinkowski_Distance(X1,X2,p,W):
""""
Returns list of weighted minkowski distance of order 'p'
between two corresponding vectors weighted by W of
two arrays

PARAMETERS
==========
X1:ndarray(dtype=int,axis=1)
input array with more than 1 dimension

X2:ndarray(dtype=int,axis=1)
input array with more than 1 dimension

p:float
input order value between 1 and 2 inclusive

W:array(dtype=int,axis=1)
input 1 dimensional array

RETURNS
=========

distance:list
Returns the list of weighted minkowski distance
between two corresponding vectors of
two arrays
"""
distance=[]
for i in range(len(X1)):
single=0
single=np.sum((abs(W*(X1[i]-X2[i])))**p)
distance.append((single)**(1/p))
return(distance)