Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
def get_closest_neighbors(model, entityid, k, type_="item"):
if type_ == "item":
inner_entity_id = model.trainset.to_inner_iid(entityid)
inner_entity_id = model.trainset.to_inner_uid(entityid)
closest_entity_id = model.get_neighbors(inner_entity_id, k)
if type_ == "item":
return [model.trainset.to_raw_iid(id_) for id_ in closest_entity_id]
return [model.trainset.to_raw_uid(id_) for id_ in closest_entity_id]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment