4

I Have an object with a set of parameters like:

var obj = new {Param1 = 100; Param2 = 212; Param3 = 311; param4 = 11; Param5 = 290;}

On the other side i have a list of object:

var obj1  = new {Param1 = 1221 ; Param2 = 212 ; Param3 = 311 ; param4 = 11  ; Param5 = 290 ; }
var obj3  = new {Param1 = 35   ; Param2 = 11  ; Param3 = 319 ; param4 = 211 ; Param5 = 790 ; }
var obj4  = new {Param1 = 126  ; Param2 = 218 ; Param3 = 2   ; param4 = 6   ; Param5 = 190 ; }
var obj5  = new {Param1 = 213  ; Param2 = 121 ; Param3 = 61  ; param4 = 11  ; Param5 = 29  ; }
var obj7  = new {Param1 = 161  ; Param2 = 21  ; Param3 = 71  ; param4 = 51  ; Param5 = 232 ; }
var obj9  = new {Param1 = 891  ; Param2 = 58  ; Param3 = 311 ; param4 = 21  ; Param5 = 590 ; }
var obj11 = new {Param1 = 61   ; Param2 = 212 ; Param3 = 843 ; param4 = 89  ; Param5 = 210 ; }

What is the best (easiest) algorithm to find the closest match for the first obj in the listed objects?

Shrayas
  • 6,784
  • 11
  • 37
  • 54
Faris Zacina
  • 14,056
  • 7
  • 62
  • 75
  • 1
    How do you define closest match? Minimum squared error? Minimum Error? Highest number of exact parameter matches (with optional tie-breaker rules)? – Brian Jun 09 '10 at 16:49
  • Related: http://stackoverflow.com/questions/2981743/ways-to-calculate-similarity/2981772#2981772 – Betamoo Jun 09 '10 at 17:02
  • Related: http://stackoverflow.com/questions/2887541/similarity-in-data-mining – Betamoo Jun 09 '10 at 17:11

3 Answers3

4

You must define the term closest match before trying to find it!!



1- One way many people use is Mean Squared Error (or Euclidean Distance) :

Calculate mean square error for all objects:

Sqr(obj.Param1-obj1.Param1) + Sqr(obj.Param2-obj1.Param2) + ..... // for obj1
Sqr(obj.Param1-obj2.Param1) + Sqr(obj.Param2-obj2.Param2) + ..... // for obj2

and choose the one with the minimum value...



2- You may also use Minimum absolute error :

Abs(obj.Param1-obj1.Param1) + Abs(obj.Param2-obj1.Param2) + ..... // for obj1
Abs(obj.Param1-obj2.Param1) + Abs(obj.Param2-obj2.Param2) + ..... // for obj2

and choose the one with the minimum value...



3- Also you can apply k-nearest neighbour with any criteria you have chosen above



It all depends on the properties of these parameters...

For more reading you may look at List of Classification algorithms

Betamoo
  • 14,964
  • 25
  • 75
  • 109
1

You could also use the Euclidean Distance.

Essentially you pretend each object is a point in 5 dimensions and look for the point that's closest (i.e.: has the shortest distance).

Ben S
  • 68,394
  • 30
  • 171
  • 212
1

Depends, i guess. Several possibilities come to my mind:

  • SAD: calculate the absolute difference of each pair of parameters (the one you test and each of your candidates) and sum them up. Lowest number is closest
  • L2-Norm: Calculate the difference of each pair of parameters, square them, sum them up, take square root
  • Cosine: Multiply each parameter with the other parameter, sum up. Divide result by product of length (L2-Norm) of both objects

of course, there are thousand more possibilities, therefore you have to specify, what you want exactly!

zerm
  • 2,812
  • 25
  • 17