Created
March 15, 2022 12:14
-
-
Save jeanmidevacc/4d3ad98b27365b04e646d6862f4c2dc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_closest_neighbors(model, entityid, k, type_="item"): | |
if type_ == "item": | |
inner_entity_id = model.trainset.to_inner_iid(entityid) | |
else: | |
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] | |
else: | |
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