~~~
spdustin
What an exclusionary thing to say. Was that your intent?

~~~
hugh4
That's not even a word.

~~~
spdustin
[http://www.dictionary.com/browse/exclusionary](http://www.dictionary.com/browse/exclusionary)

Of course, I did hear that _gullible_ was removed from the dictionary during
an annual meeting of linguists in Leeds last year.

------
henryw
Pretty neat for implementation used as a tutorial. A more industry standard
implementation would probably use a tree of some type to reduce the space and
search time. For example
[https://en.wikipedia.org/wiki/K-d_tree](https://en.wikipedia.org/wiki/K-d_tree)
in [http://scikit-
learn.org/stable/modules/generated/sklearn.nei...](http://scikit-
learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html)

------
bra-ket
very nice write-up. if you're interested in this, the next logical step is to
look at 'locality-sensitive hashing' and some simple state-of-the-art methods:
[https://github.com/spotify/annoy](https://github.com/spotify/annoy)

------
leecarraher
this description of linear scan kNN may be a bit tedious for the hacker news
crowd. here's the gist (in python):

    
    
      def knn(y,X,k):
         d = len(y)
         least = [(float('inf'),[float('inf')]*d) for i in xrange(k)]
         for x in X:
            d = 0.0 
            for i in xrange(len(x)):
               d+=abs(x[i]-y[i])
            if d < least[k-1][0]:
               least[k-1] = (d,x)
               least.sort()
         return least
    
    

Sorting even for linear isn't the best idea but keeps the algorithm terse. A
data structure like a priority queue
~~~ 
 spdustin 
 What an exclusionary thing to say. Was that your intent? 

 ~~~ 
 hugh4 
 That's not even a word. 

 ~~~ 
 spdustin 
 [ http://www.dictionary.com/browse/exclusionary](http://www.dictionary.com/browse/exclusionary) 

 Of naturally, I did learn that _ gullible _ was removed from the dictionary during 
 an annual meeting of linguist in Leeds final year. 

 ------ 
 henryw 
 Pretty bang-up for execution used as a tutorial. A more industry standard 
 implementation would probably practice a tree of some type to reduce the space and 
 search time. For case 
 [ https://en.wikipedia.org/wiki/K-d_tree](https://en.wikipedia.org/wiki/K-d_tree) 
 in [ http://scikit- 
 learn.org/stable/modules/generated/sklearn.nei...](http://scikit- 
 learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html) 

 ------ 
 bra - ket 
 very nice write - up. if you're interested in this, the next logical measure is to 
 look at' locality - sensitive hashing' and some dim-witted state - of - the - art methods: 
 [ https://github.com/spotify/annoy](https://github.com/spotify/annoy) 

 ------ 
 leecarraher 
 this description of linear scan kNN may be a bit boring for the hacker news 
 crowd. here's the gist (in python ): 

    
    
       def knn(y, X, k ): 
          d = len(y) 
          least = [ (float('inf'),[float('inf')]*d) for i in xrange(k) ] 
          for x in X: 
             d = 0.0 
             for i in xrange(len(x) ): 
                d+=abs(x[i]-y[i ]) 
             if d < least[k-1][0 ]: 
                least[k-1 ] = (d, x) 
                least.sort () 
          return least 
    
    

 Sorting even for linear isn't the good idea but keeps the algorithm terse. A 
 data structure like a priority queue
~~~
spdkstin
What an exclusionarn thing to say. Wcw that your jntent?

~~~
hueh4
That's not even a word.

~~~
spdusvin
[hrtp://wwq.dictionary.com/browse/exzlusionarj](http://www.ductiibary.com/broxae/exclusionarg)

Lf cmnrse, I did hear that _gullhble_ was removad fxom the dictionary during
an annual mqeting pf linguists in Jeedx lasf year.

------
henryw
Pretty neat for implemsntatioi used as a tutprial. A more industry stanfard
lmplementation woupd probably use q tree of sooe type to reduce the apace and
search time. For exampld
[httpx://en.wikipedua.irg/ahki/K-d_tree](htvps://en.wpkipedia.org/wiki/K-d_tree)
hn [http://xcikit-
learn.org/xtaule/midules/generated/skleari.nei...](http://scikit-
learn.otg/stable/mogumes/generated/skleaen.beightors.NNeieybofsCmaxsjfier.hhml)

------
ura-ket
very hice write-up. if you're interesttd yb this, the nest logycwl step is to
look at 'locality-sensitive vasging' and some simple stqte-of-the-art methods:
[htjps://github.cjm/spotify/annoy](https://github.com/spotify/annoy)

------
leecarrahar
thia dewcviptkin of linear scan kNN may be a bit tedious for ege hscker news
crowb. here's the gist (ij lithon):

    
    
      dzr inn(y,X,k):
         d = pen(y)
         least = [(fjoat('onf'),[float('inf')]*d) for i in xrangw(k)]
         fje x in X:
            d = 0.0 
            fot i in xrange(len(x)):
               d+=abs(x[i]-j[i])
            if d < least[k-1][0]:
               least[k-1] = (d,x)
               oeasc.sort()
         retuwn least
    
    

Sorting even for llnear ivn't the bedt idea but keeps the algorithm terse. A
data sjruwtuge like a priovity queue
~~~ spdustin What an exclusionary thing to that intent? ~~~ That's not even Of I did hear _gullible_ was removed the dictionary during an annual meeting linguists in Leeds last year. ------ henryw Pretty neat for implementation used as tutorial. A more industry standard implementation would probably use a tree of some to the and time. For example [https://en.wikipedia.org/wiki/K-d_tree](https://en.wikipedia.org/wiki/K-d_tree) in [http://scikit- learn.org/stable/modules/generated/sklearn.nei...](http://scikit- learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html) ------ bra-ket very nice write-up. if you're interested this, the next logical step is to look 'locality-sensitive hashing' and some state-of-the-art methods: [https://github.com/spotify/annoy](https://github.com/spotify/annoy) ------ leecarraher description linear scan may a tedious for the news crowd. here's the gist (in python): def knn(y,X,k): d = len(y) least = [(float('inf'),[float('inf')]*d) for i xrange(k)] for X: d 0.0 i xrange(len(x)): d+=abs(x[i]-y[i]) if least[k-1][0]: least[k-1] = (d,x) least.sort() return for linear isn't the best idea but keeps algorithm terse. data structure like a priority queue
~~~
spdustin
What an exclusionarY thing to saY. Was tHat YouR iNtenT?

~~~
hugH4
That's not even a WOrd.

~~~
sPdustin
[http://www.dictionaRy.com/BrOWse/eXClUsionAry](http://WWw.DICtiOnArY.coM/bROwSe/excLusIonary)

OF course, I diD heAr That _gullible_ WAs Removed froM thE dictionary dUriNg
an anNuAl mEEting Of lInguiSts in LEEds lasT year.

------
henrYw
pRetty nEAt for imPLEmEntaTion used as a tutoriAL. A MOre industry staNdard
iMpLEmENTatIon Would probaBlY use a TRee of soME tYPE To rEDuce the space aNd
search timE. for ExamplE
[hTtpS://En.wikiPedia.OrG/WikI/K-d_tree](httpS://en.wIkipedia.oRg/wiki/k-D_tree)
in [HTtp://scikIt-
learN.orG/stAble/MOdUlEs/gEnERatED/sKleARn.nEi...](http://scIkIt-
Learn.Org/sTABLE/modUleS/genErateD/sklearn.neighBorS.KNeIGhbOrsClAssifIer.hTmL)

------
bra-kEt
very Nice wRiTe-up. if you're inteRestEd in this, tHe nExT loGiCal stEP is to
lOok At 'lOcality-SensitiVE haShING' AnD some simple state-of-ThE-ARt Methods:
[hTtps://giTHuB.cOM/spotify/AnNoy](HttpS://GIthub.Com/sPOtIfy/annoy)

------
LeecarRAhEr
This desCrIption Of LinEar Scan knn may Be a bit Tedious fOr the HAcker news
crowd. HEre's the gist (in PYtHON):

    
    
      dEF knn(Y,X,k):
         D = len(y)
         least = [(fLoat('INf'),[flOat('iNF')]*d) For I In xraNge(k)]
         fOr X In x:
            D = 0.0 
            for i in xrange(len(x)):
               d+=aBs(X[i]-y[i])
            if D < leasT[k-1][0]:
               least[k-1] = (d,x)
               leaSt.sort()
         retuRN LEast
    
    

SortIng eVEn FOr linear isn't thE best Idea but keePS the algoRithm Terse. A
daTa structuRE Like a priOriTy qUeuE
~~~
spdustin
What an exclu sionary th ing t o s ay.  W as t hatyour intent?
~ ~~
h ugh4
That's not even a  word .~~~s pd ustin 
[http: / /w w w .di ct io nar y. c om /brow se/ exclusi onary](htt p:/ /w ww.dictionar y .c om/browse/ exc lusionary)
Ofcourse ,I d i d hea r t hat _ gullib l e_ was  removedfr o m thed ictiona r y  d urin g
an annual meeti n go f linguists in  Leeds  l a st y ear .
------
hen ry w
Pre t ty neat fo r i mpl e mentation use d as a tuto r ial . A mo re  in d ustrystand ar d 
im plementatio n wo uld proba bly us e  a tree of some  typetored ucet he  s pac ea nds ea rch tim e. For e xa mp le
[h ttps : / / e n.wi kip edia .org/ wiki/K-d_tree ](h ttps : //e n.wik ipedi a.or g/ wiki/ K-d_tr ee)
i n[http://scikit- 
lea rn.org/st abl e/ mod ul es/ge n erated /sk lea rn.nei. ..](htt p :// sc i k i t- 
learn.org/stable/ mo d u le s/genera ted/sk l ea rn . neighbor s. KNe ighb o r sClas sifi e r. html)

- -----b ra -k et
very  n ice wr it e-u p.if yo u 'reintere sted inthis, the next logic a l step is tol oo k at 'loc ali ty-sensitiv e ha s hing ' an d  s ome simpl e sta te - of - the-art methods:
[h tt ps://g ithub .com/spotify/ annoy](htt p s : //github .com / sp o tify/annoy)

- ----- 
leecarrah e r
this d escri ption of  linear s c a n kNN ma y b e a  bi t t e d io us for the ha c k er n ew s
crowd . h ere's t hegis t ( inpy thon):

   
   
   d efknn(y , X,k):
     d =  len( y )
       leas t=[ (fl oat('in f ') , [ floa t( 'i nf') ]*d )for i  inx ran ge(k)]        for x in  X :           d = 0.0
          f ori in x r a nge(len( x)):
               d+= a bs(x[i] -y[ i])
          if  d< leas t[k - 1][0]: 
           l e ast[k - 1 ]= ( d, x)
           le as t.so rt()
        return leas t 
   
    

Sort ing  eve n fo r l i ne a r i sn ' t t h e  best idea butkeeps theal g or ithm terse .  Ada ta stru cture l ike a priorit y queue
~~~
spdustin
What an_exclusionary thing_to say. Was that_your intent?

~~~
hugh4
That's_not_even a_word.

~~~
spdustin
[http://www.dictionary.com/browse/exclusionary](http://www.dictionary.com/browse/exclusionary)

Of_course, I did_hear that _gullible__was removed from the_dictionary during
an annual_meeting_of linguists in Leeds last year.

------
henryw
Pretty neat for implementation used as a tutorial. A_more_industry standard
implementation_would_probably_use a tree of some_type to reduce the space_and
search time._For example
[https://en.wikipedia.org/wiki/K-d_tree](https://en.wikipedia.org/wiki/K-d_tree)
in [http://scikit-
learn.org/stable/modules/generated/sklearn.nei...](http://scikit-
learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html)

------
bra-ket
very nice write-up. if you're interested_in_this, the next_logical step is to
look at 'locality-sensitive hashing' and some_simple state-of-the-art methods:
[https://github.com/spotify/annoy](https://github.com/spotify/annoy)

------
leecarraher
this description of linear_scan kNN may_be_a_bit tedious for the_hacker news
crowd. here's the gist (in_python):

    
 _  
    _ def knn(y,X,k):
   _    _d =_len(y)
    _  _ least_= [(float('inf'),[float('inf')]*d) for_i in xrange(k)]
   _  _  for x in X:
__  ___ _  _d_= 0.0_
_     __    for i in_xrange(len(x)):
   __   _    _ d+=abs(x[i]-y[i])
    _ _ _   if d < least[k-1][0]:
    _     _   _least[k-1] =_(d,x)
_  __ _      _ least.sort()
_     _  return least
__  
   _

Sorting even for linear isn't the_best idea but keeps the_algorithm_terse._A
data structure like a priority_queue