# Mean Average Precision python code

How do you compute MAP in python for evaluating recommender system effectiveness? Is there any library in sklearn or code in python for it?

I would like to compute the effectiveness of my Recommender System by computing Mean Average Precision.

This library called Metrics provides most of metrics for Machine Learning including MAP for Recommendation systems. If you only interested in metrics for recommendation systems, perhaps you can see this library.

• Can i get proper implementation with python code.I am not able to get any references for it? – SARTHAK Jan 30 '19 at 7:17
• That library I recommended has all python implementation, what do you mean? have you checked those github pages? Click on "Metrics", or 'this library" and you see. – TwinPenguins Jan 30 '19 at 16:58

You can use the ml_metrics library. For install this library use:

pip install ml_metrics

import ml_metrics

ml_metrics.mapk(actual, predicted, k)


What about the Mean Average Precision for binary classification ? In this case, the Average Precision for a list L of size N is the mean of the precision@k for k from 1 to N where L[k] is a True Positive. Is there any (open source) reliable implementation ? In the library mentioned in the thread, I couldn't any implementation of this metric, according to my definition above.