statisticianinstilettos / recmetrics

A library of metrics for evaluating recommender systems
MIT License
568 stars 98 forks source link

Personalization metric calculation optimization #35

Closed ibuda closed 3 years ago

ibuda commented 3 years ago

Hi @statisticianinstilettos,

kudos for a great tool! I would like to propose an optimization for calculating Personalization Metric here:

#get indicies for upper right triangle w/o diagonal
upper_right = np.triu_indices(similarity.shape[0], k=1)

#calculate average similarity
personalization = np.mean(similarity[upper_right])
return 1-personalization

There is no need to get the upper triangle indices, as the cosine similarity is a symmetric distance. I will follow up with a pull request for this.

statisticianinstilettos commented 3 years ago

great update! Thanks