Skip to content

Instantly share code, notes, and snippets.

@fmacias64
Forked from hamilton/lsh_example.py
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save fmacias64/ae1cb61d37af62d76ef3 to your computer and use it in GitHub Desktop.

Select an option

Save fmacias64/ae1cb61d37af62d76ef3 to your computer and use it in GitHub Desktop.
import lsh
lsh_machine = lsh.LSH(assignment_name="example")
# data is a dictionary of the form:
#{user_id: set([item_id1, item_id2, ...]), ...}
# Depending on the input size, training can take a while.
# But it will use all your cores to do so, and will
# automatically cache the data for assignment_name. This
# means you only need to process data once,
# and you can add more as it comes.
lsh_machine.bin_data(data, dims=largest_item_id_number)
# now supply a key and data point:
lsh.near_neighbors(some_user_id, data[some_user_id])
# just like that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment