-
-
Save fenxouxiaoquan/3f189f25a97d34fe868f892e2d2633bd to your computer and use it in GitHub Desktop.
Ranking Metrics
This file contains hidden or 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 mean_reciprocal_rank(rs): | |
| """Score is reciprocal of the rank of the first relevant item | |
| First element is "rank 1" so as to not result in infinity. Relevance is | |
| binary (nonzero is relevant). | |
| Example from http://en.wikipedia.org/wiki/Mean_reciprocal_rank | |
| >>> rs = [[0, 0, 1], [0, 1, 0], [1, 0, 0]] | |
| >>> mean_reciprocal_rank(rs) | |
| 0.6111111111111112 | |
| Args: | |
| rs: List of relevance scores in rank order (first element is the first item) | |
| Returns: | |
| Mean reciprocal rank | |
| """ | |
| return np.mean([1. / (np.asfarray(r).nonzero()[0] + 1) for r in rs]) | |
| def rank_precision_k(): | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment