'Compute Similarity(percentage) between two Matrix/Array
How to compute similarity(percentage) between two matrix/arrays. or find the closest array/matrix to a given array, on the basis of how similar their data values are.
I have tried manhattan distance. but want a more complex algorithm. it could also be thought of as a classification problem.
Matrix
A1: [ [ 2 , 4 ] , [ 3 , 6.3 ] ]
B1: [ [ 2 , 2 ] , [ 5 , 4.9 ] ]
C1: [ [ 1 , 5 ] , [ 4.2 , 5.8 ] ]
compare with
i1: [ [ 2 , 4.3 ] , [ 4.8 , 5.5 ] ]
should return the matrix closest to i1: => 1,2,3 and their similarity coefficient
Solution 1:[1]
If I understand you right, you can use Manhattan metric:
from neulab.Algorithms import ManhattanMetric
i1 = [[2 , 4], [3 , 6.3]]
A1 = [[2 , 4 ] , [3 , 6.3]]
B1 = [[2 , 2 ] , [5 , 4.9]]
C1 = [[1 , 5 ] , [4.2 , 5.8]]
d1 = ManhattanMetric(vector1=i1, vector2=A1)
d2 = ManhattanMetric(vector1=i1, vector2=B1)
d3 = ManhattanMetric(vector1=i1, vector2=C1)
Will return
d1 = 0.0, d2 = 5.3999999999999995, d3 = 3.7
Or you can use other metrics. See https://pypi.org/project/neulab/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |