Пример #1
0
  def GetNeighbors(self, example):
    """ Returns the k nearest neighbors of the example

    """
    nbrs = TopNContainer(self._k)
    for trex in self._trainingExamples:
      dist = self._dfunc(trex, example, self._attrs)
      if self._radius is None or dist < self._radius:
        nbrs.Insert(-dist, trex)
    nbrs.reverse()
    return [x for x in nbrs]
Пример #2
0
    def GetNeighbors(self, example):
        """ Returns the k nearest neighbors of the example

    """
        nbrs = TopNContainer(self._k)
        for trex in self._trainingExamples:
            dist = self._dfunc(trex, example, self._attrs)
            if self._radius is None or dist < self._radius:
                nbrs.Insert(-dist, trex)
        nbrs.reverse()
        return [x for x in nbrs]
Пример #3
0
 def test5(self):
   """ random test with extras and getitem, include reverse"""
   cont = TopNContainer(10)
   for i in range(100):
     v = random.random()
     cont.Insert(v,v+1)
   cont.reverse()
   lastV,lastE = cont[0]
   for i in range(1,len(cont)):
     v,e = cont[i]
     assert v<=lastV
     assert e<=lastE
     lastV,lastE = v,e
Пример #4
0
 def test5(self):
     # random test with extras and getitem, include reverse
     cont = TopNContainer(10)
     for i in range(100):
         v = random.random()
         cont.Insert(v, v + 1)
     cont.reverse()
     lastV, lastE = cont[0]
     for i in range(1, len(cont)):
         v, e = cont[i]
         assert v <= lastV
         assert e <= lastE
         lastV, lastE = v, e