Skip to content

Instantly share code, notes, and snippets.

@finnp
Created August 25, 2015 13:54
Show Gist options
  • Save finnp/780a48a46366be0f7a72 to your computer and use it in GitHub Desktop.
Save finnp/780a48a46366be0f7a72 to your computer and use it in GitHub Desktop.
def knearest(r_id, set_of_restaurants, db, k = 7, reg = 3.):
def getTupel(r):
sim, support = db.get(r_id, r)
shrunken_sim = shrunk_sim(sim, support, reg)
return (r, shrunken_sim, support)
rs = [getTupel(r) for r in set_of_restaurants]
return sorted(rs, key=lambda r: -r[1])[:k]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment