{
  "id": 9584,
  "title": "Average Precision at k (AP@k) ",
  "url": "/competitions/avito-prohibited-content/discussion/9584",
  "author_name": "",
  "post_date": "2014-06-27T04:37:35.103Z",
  "votes": null,
  "comment_count": 25,
  "views": 15131,
  "content": "<p>Can anyone elaborate on what this metric is?</p>\n<p>Thanks</p>",
  "messages": [
    {
      "id": "49671",
      "postDate": "06/27/2014 04:37:35",
      "content": "<p>Can anyone elaborate on what this metric is?</p>\n<p>Thanks</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "49680",
      "postDate": "06/27/2014 06:51:40",
      "content": "<p>There is a good article here: https://sanchom.wordpress.com/tag/average-precision/</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "49723",
      "postDate": "06/27/2014 19:54:07",
      "content": "<p>I'm not clear how this metric is calculated&nbsp;for the public LB. I can see two different ways the scores for the LB could be generated:</p>\n\n<p>1. The top 32500 ads of a submission are taken for the metric, the rest are discarded. The score for the public leaderboard is the precision for the ads that appear in the public LB set. The ads that appear in the private LB set are ignored.</p>\n\n<p>2. The ads that are part of the public LB set are taken from the submission for the metric, the rest are discarded. The top 32500 public LB ads are used to score the precision.</p>\n\n<p>Could someone please clarify how the metric is computed for the LB?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "49728",
      "postDate": "06/27/2014 20:40:24",
      "content": "<p>The metric is computed for the LB exactly as you described in 2.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "49729",
      "postDate": "06/27/2014 20:51:17",
      "content": "<p>[quote=Jack Shih Tzu;49723]</p>\n<p>he top 32500 public LB ads&nbsp;</p>\n<p>[/quote]</p>\n\n<p>I'm sorry, I feel like an idiot. Where if the 32500 number coming from?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "49731",
      "postDate": "06/27/2014 20:58:05",
      "content": "<p>32500 is the value we are using for k in the AP@k metric. It is shown when you hover the &quot;Score?&quot; title in the leaderboard page. We chose that number because it approximately represents&nbsp;5% of the test data.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "49733",
      "postDate": "06/27/2014 21:10:04",
      "content": "<p><strong>Evaluating Ranked Search Engine Results</strong></p>\n<p><strong>.</strong></p>\n<p>What makes for a good search engine?</p>\n<p>.</p>\n<p>Mainly:</p>\n<ul>\n<li><span style=\"line-height: 1.4\">Speed</span></li>\n<li><span style=\"line-height: 1.4\">Size</span></li>\n<li><span style=\"line-height: 1.4\">Quality</span></li>\n</ul>\n<p>Optionally:</p>\n<ul>\n<li><span style=\"line-height: 1.4\">Personalization</span></li>\n<li><span style=\"line-height: 1.4\">Localization</span></li>\n<li><span style=\"line-height: 1.4\">Customization</span></li>\n<li><span style=\"line-height: 1.4\">Simplicity / UX</span></li>\n<li><span style=\"line-height: 1.4\">Social</span></li>\n<li><span style=\"line-height: 1.4\">Privacy</span></li>\n</ul>\n<p><span style=\"line-height: 1.4\">.</span></p>\n<p><strong>Measuring Quality</strong></p>\n<p>How de we assess the quality of a search engine result page (SERP)?</p>\n<ul>\n<li><span style=\"line-height: 1.4\">Ask users and volunteers directly for feedback</span></li>\n<li><span style=\"line-height: 1.4\">Hire SERP reviewers</span></li>\n<li><span style=\"line-height: 1.4\">Measure user engagement (Number of clicks on result, Bounce ratio)</span></li>\n<li><span style=\"line-height: 1.4\">A/B testing</span></li>\n<li><span style=\"line-height: 1.4\">Multi-variate testing</span></li>\n</ul>\n<p><span style=\"line-height: 1.4\">.</span></p>\n<p><strong>Feedback &amp; Labels</strong></p>\n<p>Quality feedback can be binary (0 for not relevant, 1 for relevant) or non-binary (0-3 scale).</p>\n<p>.</p>\n<p>Example binary feedback for 15 results:</p>\n<p>.</p>\n<p>[(1,1),(2,1),(3,1),(4,0),(5,1),(6,1),(7,1),(8,1),(9,1),(10,1),(11,0),(12,1),(13,0),(14,1),(15,0)]<br><sub>(Rank 1, 2, 3 are relevant, rank 4 is irrelevant, rank 5 to 10 are relevant etc.)</sub></p>\n<p>.</p>\n<p><strong><em>rank_eval.py</em></strong></p>\n<p>Functions for:</p>\n<ul>\n<li><span style=\"line-height: 1.4\">Precision (P)</span></li>\n<li><span style=\"line-height: 1.4\">Precision at K (PaK)</span></li>\n<li><span style=\"line-height: 1.4\">Interpolated Precision (IP)</span></li>\n<li><span style=\"line-height: 1.4\">Average Precision (AP)</span></li>\n<li><span style=\"line-height: 1.4\">Recall (R)</span></li>\n<li><span style=\"line-height: 1.4\">Cumulative Gain (CG)</span></li>\n<li><span style=\"line-height: 1.4\">Discounted Cumulative Gain (DCG)</span></li>\n<li><span style=\"line-height: 1.4\">Ideal Discounted Cumulative Gain (IDCG)</span></li>\n<li><span style=\"line-height: 1.4\">Normalized Discounted Cumulative Gain (NDCG)</span></li>\n</ul>\n<p>Sample output:</p>\n<p>.</p>\n<p><code>INPUT: [(1,1),(2,1),(3,1),(4,0),(5,1),(6,1),(7,1),(8,1),(9,1),(10,1),(11,0),(12,1),(13,0),(14,1),(15,0)]</code></p>\n<p><code>P: [1.0, 1.0, 1.0, 0.75, 0.8, 0.83, 0.85, 0.87, 0.88, 0.9, 0.81, 0.83, 0.76, 0.78, 0.73]<br>R: [0.09, 0.18, 0.27, 0.27, 0.36, 0.45, 0.54, 0.63, 0.72, 0.81, 0.81, 0.90, 0.90, 1.0, 1.0]<br>IP: [1.0, 1.0, 1.0, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.83, 0.83, 0.78, 0.78, 0.73]<br>AP: [1.0, 1.0, 1.0, 0.93, 0.90, 0.89, 0.89, 0.88, 0.88, 0.89, 0.88, 0.87, 0.87, 0.86, 0.85]<br>PaK: 0.8 // precision at 5<br>CG: 11<br>DCG: 6.69277<br>IDCG: 6.95740<br>NDCG: 0.96196</code></p>\n\n<p><code>RANK RELEVANT? PRECISION RECALL INTERPOLATED PRECISION<br>1 1 1.00000 0.09091 1.00000<br>2 1 1.00000 0.18182 1.00000<br>3 1 1.00000 0.27273 1.00000<br>4 0 0.75000 0.27273 0.90000<br>5 1 0.80000 0.36364 0.90000<br>6 1 0.83333 0.45455 0.90000<br>7 1 0.85714 0.54545 0.90000<br>8 1 0.87500 0.63636 0.90000<br>9 1 0.88889 0.72727 0.90000<br>10 1 0.90000 0.81818 0.90000<br>11 0 0.81818 0.81818 0.83333<br>12 1 0.83333 0.90909 0.83333<br>13 0 0.76923 0.90909 0.78571<br>14 1 0.78571 1.00000 0.78571<br>15 0 0.73333 1.00000 0.73333<br>.</code></p>\n<p>Further reading:</p>\n<p><a href=\"http://www.enseignement.polytechnique.fr/informatique/profs/Michalis.Vazirgiannis/course_slides/71_text.pdf\">intro-to-text-retrieval.pdf</a></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "49734",
      "postDate": "06/27/2014 21:14:59",
      "content": "<p>[quote=Luis Tandalla;49731]</p>\n<p>32500 is the value we are using for k in the AP@k metric. It is shown when you hover the &quot;Score?&quot; title in the leaderboard page. We chose that number because it approximately represents&nbsp;5% of the test data.</p>\n<p>[/quote]</p>\n\n<p>Thanks Luis. This is helpful. You might want to have that added to the evaluation page as well.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "49882",
      "postDate": "07/01/2014 00:16:07",
      "content": "<p>Hi, can anyone provide the&nbsp;AP@k evaluation code in R, C#, C, or C++ ?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "50103",
      "postDate": "07/07/2014 15:51:38",
      "content": "<p>Hi B Yang,</p>\n<p>A python code that evaluates AP@k has been posted in the <a href=\"http://www.kaggle.com/c/avito-prohibited-content/data\">Data</a>&nbsp;page.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "50347",
      "postDate": "07/11/2014 12:39:59",
      "content": "<p>In case anybody will find this usefull:</p>\n<p>&nbsp;same code posted above, except that it does not read solution and predictions from the files, but keeps solution in memory, so fast evaluation is possible.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "50361",
      "postDate": "07/11/2014 16:14:41",
      "content": "<p>Why post sample APK code to the data page when the wiki already has an implementation?&nbsp;&nbsp;https://www.kaggle.com/wiki/MeanAveragePrecision</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "50368",
      "postDate": "07/11/2014 18:53:17",
      "content": "<p>I'm having some troubles when implementing cross-validation for this competitions. Currently, I'm planning to do the following.</p>\n\n<p>Calculate the prediction probability on each&nbsp;cross-validation fold and sort those values in descending order. Next, take the top 5 percent of it and compares with top 5 percent of the actual labels. But, I don't have an idea of how to select top 5 percent of the cross-validation according the their actual probability values. Since, class label is either zero or one ( as given in the training set) once sorted the relative position of each training example in the cross-validation fold is not unique.</p>\n\n<p>You helps are highly appreciated.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "50510",
      "postDate": "07/15/2014 00:46:08",
      "content": "<p>[quote=Synthient;50361]</p>\n<p>Why post sample APK code to the data page when the wiki already has an implementation?&nbsp;&nbsp;https://www.kaggle.com/wiki/MeanAveragePrecision</p>\n<p>[/quote]</p>\n<p>I haven't looked at the code yet, but the wiki describes &quot;mean average precision&quot; while the term used for this contest&nbsp;is &quot;average precision&quot;. Are they the same thing or is there extra meaning to the word &quot;mean&quot; ?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "50919",
      "postDate": "07/20/2014 10:51:06",
      "content": "<p>It seems that something that is calculated by the APatK.py is not quite Avarage Precision at K as discribed in the article mentioned above and in wiki page&nbsp;<a href=\"http://en.wikipedia.org/wiki/Information_retrieval#Average_precision\">here</a></p>\n<p>For instance let us take an example from the article about planes and birds.</p>\n<p>The author got the answer&nbsp;0.782</p>\n<p>I've created two files solution.csv and predictions.csv which represent the same problem, set K = 10 and got answer&nbsp;0.669920634921</p>\n<p>Probably the reason for this result is that Avarage Precision at K is an integral of precision-recall curve and the given code, in fact, calculates integral of &quot;precision-shareofpositives curve&quot;.</p>\n<p>Were am I&nbsp;wrong? And if i'm right, which metric is actually used in the competition?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "50926",
      "postDate": "07/20/2014 14:28:26",
      "content": "<p><strong>&#1043;&#1077;&#1086;&#1088;&#1075;&#1080;&#1081;,&nbsp;</strong>I'm totally agree with you. Seems actual metric is <strong>NOT</strong>&nbsp;<em>average precison at K<strong>.</strong></em>&nbsp;I am not python user and tryied to cross-validate using self-programmed AvPatK metric in R. It gives&nbsp;~ 0.75 on my train set. But on public LB set I recieve ~0.9. After your post&nbsp;I checked&nbsp;python code from data page and saw that it actually calculate something like&nbsp;&quot;precision-shareofpositives curve&quot; as you pointed.</p>\n<p><strong>Organization of this competition is very very poor. Why should I browse forums to find actual metrics? Administrators, why you can't&nbsp;write and DOUBLE CHECK CORRECT&nbsp;evaluation rules, formulas and code at&nbsp;<a href=\"http://www.kaggle.com/c/avito-prohibited-content/details/evaluation\" target=\"_blank\">Evaluation page</a>?</strong></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "50935",
      "postDate": "07/20/2014 19:26:28",
      "content": "<p>As far as I can see from the given&nbsp;<strong>APatK.py</strong> code, and the discussion above in this thread, and my observation on the leaderboard, the metric goes like this:</p>\n<p>For the public leaderboard score:</p>\n<p><code>take the submission file and eliminate all ids that are not in the 50% public</code></p>\n<p><code></code><code>take the top 32500 submitted ids from what remains</code></p>\n<p><code>count the ids that are actually spam</code></p>\n<p><code>score = (number of correctly guessed spam) / 32500</code></p>\n<p>And for the private LB, just adjust the first step.</p>\n<p>Not sure if it fits the&nbsp;announced&nbsp;name academically, but this is how it's calculated as far as I can tell.</p>\n<p>By the way, I too don't think this is the best metric, that's why I <a href=\"http://www.kaggle.com/c/avito-prohibited-content/forums/t/9721/timeline-change/50803#post50803\">double checked</a>. But apparently this is what the sponsor is paying for. IMHO, good old AUC would be a better choice.</p>\n<p>Hope this helps.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "50936",
      "postDate": "07/20/2014 19:38:12",
      "content": "<p>Good old auc is like 0.99 already from the sample benchmark. &nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "50938",
      "postDate": "07/20/2014 20:08:40",
      "content": "<p>[quote=Abhishek;50936]</p>\n<p>Good old auc is like 0.99 already from the sample benchmark. &nbsp;</p>\n<p>[/quote]</p>\n<p>And with the current metric, the top score is 0.98 with 42 days to go and only 114 competitors so far. I expect to see 0.99999 close to the end.</p>\n<p>AUC takes into consideration the whole data set, that's why I suggested it would have been better. The current metric does not. I've only played with 10% of the data, and I have 0.96 on the LB.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "50976",
      "postDate": "07/21/2014 00:33:37",
      "content": "<p>To avoid any further confusion, the metric is calculated as:</p>\n<p>\\[AP@K = \\frac{\\sum_{i=1}^K P@i}{K} \\]</p>\n<p>where</p>\n<p>\\[ P@i = \\frac{ \\text{#relevant - forbidden ads retrieved in the first ith places} }{i} \\]</p>\n<p>As&nbsp;Abhishek mentioned, AUC metric would already give scores of 0.99+, so&nbsp;the differences in the top leaderboard would be in the last decimal places, and chance would play a big role at the end. The chosen metric gives a little more space to improve and to differentiate between scores.</p>\n<p>[quote=&#1043;&#1077;&#1086;&#1088;&#1075;&#1080;&#1081; &#1050;&#1072;&#1083;&#1072;&#1096;&#1085;&#1086;&#1074;;50919]</p>\n<p>The author got the answer 0.782 [but]&nbsp;got answer 0.669920634921</p>\n<p>[/quote]</p>\n<p>The definition in wikipedia,</p>\n<p>\\[AP@K = \\frac{\\sum P@i * rel(i)}{\\text{# relevant at K}} \\]</p>\n<p>would also give higher scores as AUC would, so the top leaderboard would already be populated with 0.99+ scores.&nbsp;</p>\n<p>[quote=barisumog;50938]</p>\n<p>AUC takes into consideration the whole data set.</p>\n<p>[/quote]</p>\n<p>Sometimes one may not be interested&nbsp;in the&nbsp;predictions of the whole data set but only in the most confident (top) predictions.&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51079",
      "postDate": "07/23/2014 04:42:34",
      "content": "<p>How close is your CV score to LB? And do you find it directionally correct? I just started doing some CV and I find the score off by 0.008-0.016 and not always directionally correct. I'm working with k based on 5% of my test set instead of a static 32k. So far I've only used the benchmark features.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51085",
      "postDate": "07/23/2014 09:27:52",
      "content": "<p>[quote=Giulio;51079]</p>\n<p>I find the score off by 0.008-0.016 and not always directionally correct</p>\n<p>[/quote]</p>\n<p>More or less the&nbsp;same here.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51148",
      "postDate": "07/24/2014 17:29:08",
      "content": "<p>[quote=Triskelion;49733]</p>\n<p><strong>Evaluating Ranked Search Engine Results</strong></p>\n<p><strong>.</strong></p>\n<p>What makes for a good search engine?</p>\n<p>.</p>\n<p>.</p>\n<p>.</p>\n<p>[/quote]</p>\n<p>Please forgive the newb question, but I take it that in the context of this competition and the information you provided on search engine performance that correctly predicting prohibited content is equivalent to relevance in search engine performance.</p>\n<p>Thank you</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51167",
      "postDate": "07/25/2014 06:13:19",
      "content": "<p>[quote=HeatfanJohn;51148]</p>\n<p>Please forgive the newb question, but I take it that in the context of this competition and the information you provided on search engine performance that correctly predicting prohibited content is equivalent to relevance in search engine performance.</p>\n<p>Thank you</p>\n<p>[/quote]</p>\n<p>It is much the same yes, average precision at K is a metric used in evaluating search engine relevance, and the metric in use for this competition. I suspect that Avito wants a ranked result page with illicit ads, the worst offenders on top, so moderators can act on it.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51842",
      "postDate": "08/10/2014 19:49:27",
      "content": "<p>[quote=Peter Pi&#353;ljar;50347]</p>\n<p>In case anybody will find this usefull:</p>\n<p>&nbsp;same code posted above, except that it does not read solution and predictions from the files, but keeps solution in memory, so fast evaluation is possible.</p>\n<p>[/quote]</p>\n<p>A faster implementation using cPickle and pandas :)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "52196",
      "postDate": "08/19/2014 18:22:29",
      "content": "<p>This might be a very stupid question, but I cannot figure out how to use the APatK.py file to compute a score for my solution.</p>\n<p>I understand that the predictions.csv file should be the submission file. This is the one that contains item_ids from the avito_test.tsv file, arranged in order from most illicit to least illicit content.&nbsp;</p>\n<p>However, I don't understand how to generate the solutions.tsv file.&nbsp;</p>\n\n<p>The post above says:</p>\n<p>&quot;take the submission file and eliminate all ids that are not in the 50% public</p>\n<p>take the top 32500 submitted ids from what remains</p>\n<p>count the ids that are actually spam&quot;</p>\n\n<p>Now, since the avito_test.tsv file does not mention the is_blocked parameter, how do we count the ids that are actually spam?</p>\n\n<p>Equivalently, if I look at Peter's post above, where he has attached a version of the&nbsp;APatK.py file,</p>\n<p>I don't understand how to get the&nbsp;data_test.target variable in line 6?</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 49680,
      "author_name": "sashikanthdareddy",
      "author_url": "",
      "post_date": "06/27/2014 06:51:40",
      "content": "<p>There is a good article here: https://sanchom.wordpress.com/tag/average-precision/</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 49723,
      "author_name": "tbrichie",
      "author_url": "",
      "post_date": "06/27/2014 19:54:07",
      "content": "<p>I'm not clear how this metric is calculated&nbsp;for the public LB. I can see two different ways the scores for the LB could be generated:</p>\n\n<p>1. The top 32500 ads of a submission are taken for the metric, the rest are discarded. The score for the public leaderboard is the precision for the ads that appear in the public LB set. The ads that appear in the private LB set are ignored.</p>\n\n<p>2. The ads that are part of the public LB set are taken from the submission for the metric, the rest are discarded. The top 32500 public LB ads are used to score the precision.</p>\n\n<p>Could someone please clarify how the metric is computed for the LB?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 49728,
      "author_name": "luistandalla",
      "author_url": "",
      "post_date": "06/27/2014 20:40:24",
      "content": "<p>The metric is computed for the LB exactly as you described in 2.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 49729,
      "author_name": "adjgiulio",
      "author_url": "",
      "post_date": "06/27/2014 20:51:17",
      "content": "<p>[quote=Jack Shih Tzu;49723]</p>\n<p>he top 32500 public LB ads&nbsp;</p>\n<p>[/quote]</p>\n\n<p>I'm sorry, I feel like an idiot. Where if the 32500 number coming from?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 49731,
      "author_name": "luistandalla",
      "author_url": "",
      "post_date": "06/27/2014 20:58:05",
      "content": "<p>32500 is the value we are using for k in the AP@k metric. It is shown when you hover the &quot;Score?&quot; title in the leaderboard page. We chose that number because it approximately represents&nbsp;5% of the test data.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 49733,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "06/27/2014 21:10:04",
      "content": "<p><strong>Evaluating Ranked Search Engine Results</strong></p>\n<p><strong>.</strong></p>\n<p>What makes for a good search engine?</p>\n<p>.</p>\n<p>Mainly:</p>\n<ul>\n<li><span style=\"line-height: 1.4\">Speed</span></li>\n<li><span style=\"line-height: 1.4\">Size</span></li>\n<li><span style=\"line-height: 1.4\">Quality</span></li>\n</ul>\n<p>Optionally:</p>\n<ul>\n<li><span style=\"line-height: 1.4\">Personalization</span></li>\n<li><span style=\"line-height: 1.4\">Localization</span></li>\n<li><span style=\"line-height: 1.4\">Customization</span></li>\n<li><span style=\"line-height: 1.4\">Simplicity / UX</span></li>\n<li><span style=\"line-height: 1.4\">Social</span></li>\n<li><span style=\"line-height: 1.4\">Privacy</span></li>\n</ul>\n<p><span style=\"line-height: 1.4\">.</span></p>\n<p><strong>Measuring Quality</strong></p>\n<p>How de we assess the quality of a search engine result page (SERP)?</p>\n<ul>\n<li><span style=\"line-height: 1.4\">Ask users and volunteers directly for feedback</span></li>\n<li><span style=\"line-height: 1.4\">Hire SERP reviewers</span></li>\n<li><span style=\"line-height: 1.4\">Measure user engagement (Number of clicks on result, Bounce ratio)</span></li>\n<li><span style=\"line-height: 1.4\">A/B testing</span></li>\n<li><span style=\"line-height: 1.4\">Multi-variate testing</span></li>\n</ul>\n<p><span style=\"line-height: 1.4\">.</span></p>\n<p><strong>Feedback &amp; Labels</strong></p>\n<p>Quality feedback can be binary (0 for not relevant, 1 for relevant) or non-binary (0-3 scale).</p>\n<p>.</p>\n<p>Example binary feedback for 15 results:</p>\n<p>.</p>\n<p>[(1,1),(2,1),(3,1),(4,0),(5,1),(6,1),(7,1),(8,1),(9,1),(10,1),(11,0),(12,1),(13,0),(14,1),(15,0)]<br><sub>(Rank 1, 2, 3 are relevant, rank 4 is irrelevant, rank 5 to 10 are relevant etc.)</sub></p>\n<p>.</p>\n<p><strong><em>rank_eval.py</em></strong></p>\n<p>Functions for:</p>\n<ul>\n<li><span style=\"line-height: 1.4\">Precision (P)</span></li>\n<li><span style=\"line-height: 1.4\">Precision at K (PaK)</span></li>\n<li><span style=\"line-height: 1.4\">Interpolated Precision (IP)</span></li>\n<li><span style=\"line-height: 1.4\">Average Precision (AP)</span></li>\n<li><span style=\"line-height: 1.4\">Recall (R)</span></li>\n<li><span style=\"line-height: 1.4\">Cumulative Gain (CG)</span></li>\n<li><span style=\"line-height: 1.4\">Discounted Cumulative Gain (DCG)</span></li>\n<li><span style=\"line-height: 1.4\">Ideal Discounted Cumulative Gain (IDCG)</span></li>\n<li><span style=\"line-height: 1.4\">Normalized Discounted Cumulative Gain (NDCG)</span></li>\n</ul>\n<p>Sample output:</p>\n<p>.</p>\n<p><code>INPUT: [(1,1),(2,1),(3,1),(4,0),(5,1),(6,1),(7,1),(8,1),(9,1),(10,1),(11,0),(12,1),(13,0),(14,1),(15,0)]</code></p>\n<p><code>P: [1.0, 1.0, 1.0, 0.75, 0.8, 0.83, 0.85, 0.87, 0.88, 0.9, 0.81, 0.83, 0.76, 0.78, 0.73]<br>R: [0.09, 0.18, 0.27, 0.27, 0.36, 0.45, 0.54, 0.63, 0.72, 0.81, 0.81, 0.90, 0.90, 1.0, 1.0]<br>IP: [1.0, 1.0, 1.0, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.83, 0.83, 0.78, 0.78, 0.73]<br>AP: [1.0, 1.0, 1.0, 0.93, 0.90, 0.89, 0.89, 0.88, 0.88, 0.89, 0.88, 0.87, 0.87, 0.86, 0.85]<br>PaK: 0.8 // precision at 5<br>CG: 11<br>DCG: 6.69277<br>IDCG: 6.95740<br>NDCG: 0.96196</code></p>\n\n<p><code>RANK RELEVANT? PRECISION RECALL INTERPOLATED PRECISION<br>1 1 1.00000 0.09091 1.00000<br>2 1 1.00000 0.18182 1.00000<br>3 1 1.00000 0.27273 1.00000<br>4 0 0.75000 0.27273 0.90000<br>5 1 0.80000 0.36364 0.90000<br>6 1 0.83333 0.45455 0.90000<br>7 1 0.85714 0.54545 0.90000<br>8 1 0.87500 0.63636 0.90000<br>9 1 0.88889 0.72727 0.90000<br>10 1 0.90000 0.81818 0.90000<br>11 0 0.81818 0.81818 0.83333<br>12 1 0.83333 0.90909 0.83333<br>13 0 0.76923 0.90909 0.78571<br>14 1 0.78571 1.00000 0.78571<br>15 0 0.73333 1.00000 0.73333<br>.</code></p>\n<p>Further reading:</p>\n<p><a href=\"http://www.enseignement.polytechnique.fr/informatique/profs/Michalis.Vazirgiannis/course_slides/71_text.pdf\">intro-to-text-retrieval.pdf</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 49734,
      "author_name": "adjgiulio",
      "author_url": "",
      "post_date": "06/27/2014 21:14:59",
      "content": "<p>[quote=Luis Tandalla;49731]</p>\n<p>32500 is the value we are using for k in the AP@k metric. It is shown when you hover the &quot;Score?&quot; title in the leaderboard page. We chose that number because it approximately represents&nbsp;5% of the test data.</p>\n<p>[/quote]</p>\n\n<p>Thanks Luis. This is helpful. You might want to have that added to the evaluation page as well.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 49882,
      "author_name": "byang1",
      "author_url": "",
      "post_date": "07/01/2014 00:16:07",
      "content": "<p>Hi, can anyone provide the&nbsp;AP@k evaluation code in R, C#, C, or C++ ?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 50103,
      "author_name": "luistandalla",
      "author_url": "",
      "post_date": "07/07/2014 15:51:38",
      "content": "<p>Hi B Yang,</p>\n<p>A python code that evaluates AP@k has been posted in the <a href=\"http://www.kaggle.com/c/avito-prohibited-content/data\">Data</a>&nbsp;page.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 50347,
      "author_name": "peterpisljar",
      "author_url": "",
      "post_date": "07/11/2014 12:39:59",
      "content": "<p>In case anybody will find this usefull:</p>\n<p>&nbsp;same code posted above, except that it does not read solution and predictions from the files, but keeps solution in memory, so fast evaluation is possible.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 50361,
      "author_name": "brundage",
      "author_url": "",
      "post_date": "07/11/2014 16:14:41",
      "content": "<p>Why post sample APK code to the data page when the wiki already has an implementation?&nbsp;&nbsp;https://www.kaggle.com/wiki/MeanAveragePrecision</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 50368,
      "author_name": "upulbandara",
      "author_url": "",
      "post_date": "07/11/2014 18:53:17",
      "content": "<p>I'm having some troubles when implementing cross-validation for this competitions. Currently, I'm planning to do the following.</p>\n\n<p>Calculate the prediction probability on each&nbsp;cross-validation fold and sort those values in descending order. Next, take the top 5 percent of it and compares with top 5 percent of the actual labels. But, I don't have an idea of how to select top 5 percent of the cross-validation according the their actual probability values. Since, class label is either zero or one ( as given in the training set) once sorted the relative position of each training example in the cross-validation fold is not unique.</p>\n\n<p>You helps are highly appreciated.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 50510,
      "author_name": "byang1",
      "author_url": "",
      "post_date": "07/15/2014 00:46:08",
      "content": "<p>[quote=Synthient;50361]</p>\n<p>Why post sample APK code to the data page when the wiki already has an implementation?&nbsp;&nbsp;https://www.kaggle.com/wiki/MeanAveragePrecision</p>\n<p>[/quote]</p>\n<p>I haven't looked at the code yet, but the wiki describes &quot;mean average precision&quot; while the term used for this contest&nbsp;is &quot;average precision&quot;. Are they the same thing or is there extra meaning to the word &quot;mean&quot; ?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 50919,
      "author_name": "user173369",
      "author_url": "",
      "post_date": "07/20/2014 10:51:06",
      "content": "<p>It seems that something that is calculated by the APatK.py is not quite Avarage Precision at K as discribed in the article mentioned above and in wiki page&nbsp;<a href=\"http://en.wikipedia.org/wiki/Information_retrieval#Average_precision\">here</a></p>\n<p>For instance let us take an example from the article about planes and birds.</p>\n<p>The author got the answer&nbsp;0.782</p>\n<p>I've created two files solution.csv and predictions.csv which represent the same problem, set K = 10 and got answer&nbsp;0.669920634921</p>\n<p>Probably the reason for this result is that Avarage Precision at K is an integral of precision-recall curve and the given code, in fact, calculates integral of &quot;precision-shareofpositives curve&quot;.</p>\n<p>Were am I&nbsp;wrong? And if i'm right, which metric is actually used in the competition?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 50926,
      "author_name": "dselivanov",
      "author_url": "",
      "post_date": "07/20/2014 14:28:26",
      "content": "<p><strong>&#1043;&#1077;&#1086;&#1088;&#1075;&#1080;&#1081;,&nbsp;</strong>I'm totally agree with you. Seems actual metric is <strong>NOT</strong>&nbsp;<em>average precison at K<strong>.</strong></em>&nbsp;I am not python user and tryied to cross-validate using self-programmed AvPatK metric in R. It gives&nbsp;~ 0.75 on my train set. But on public LB set I recieve ~0.9. After your post&nbsp;I checked&nbsp;python code from data page and saw that it actually calculate something like&nbsp;&quot;precision-shareofpositives curve&quot; as you pointed.</p>\n<p><strong>Organization of this competition is very very poor. Why should I browse forums to find actual metrics? Administrators, why you can't&nbsp;write and DOUBLE CHECK CORRECT&nbsp;evaluation rules, formulas and code at&nbsp;<a href=\"http://www.kaggle.com/c/avito-prohibited-content/details/evaluation\" target=\"_blank\">Evaluation page</a>?</strong></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 50935,
      "author_name": "barisumog",
      "author_url": "",
      "post_date": "07/20/2014 19:26:28",
      "content": "<p>As far as I can see from the given&nbsp;<strong>APatK.py</strong> code, and the discussion above in this thread, and my observation on the leaderboard, the metric goes like this:</p>\n<p>For the public leaderboard score:</p>\n<p><code>take the submission file and eliminate all ids that are not in the 50% public</code></p>\n<p><code></code><code>take the top 32500 submitted ids from what remains</code></p>\n<p><code>count the ids that are actually spam</code></p>\n<p><code>score = (number of correctly guessed spam) / 32500</code></p>\n<p>And for the private LB, just adjust the first step.</p>\n<p>Not sure if it fits the&nbsp;announced&nbsp;name academically, but this is how it's calculated as far as I can tell.</p>\n<p>By the way, I too don't think this is the best metric, that's why I <a href=\"http://www.kaggle.com/c/avito-prohibited-content/forums/t/9721/timeline-change/50803#post50803\">double checked</a>. But apparently this is what the sponsor is paying for. IMHO, good old AUC would be a better choice.</p>\n<p>Hope this helps.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 50936,
      "author_name": "abhishek",
      "author_url": "",
      "post_date": "07/20/2014 19:38:12",
      "content": "<p>Good old auc is like 0.99 already from the sample benchmark. &nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 50938,
      "author_name": "barisumog",
      "author_url": "",
      "post_date": "07/20/2014 20:08:40",
      "content": "<p>[quote=Abhishek;50936]</p>\n<p>Good old auc is like 0.99 already from the sample benchmark. &nbsp;</p>\n<p>[/quote]</p>\n<p>And with the current metric, the top score is 0.98 with 42 days to go and only 114 competitors so far. I expect to see 0.99999 close to the end.</p>\n<p>AUC takes into consideration the whole data set, that's why I suggested it would have been better. The current metric does not. I've only played with 10% of the data, and I have 0.96 on the LB.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 50976,
      "author_name": "luistandalla",
      "author_url": "",
      "post_date": "07/21/2014 00:33:37",
      "content": "<p>To avoid any further confusion, the metric is calculated as:</p>\n<p>\\[AP@K = \\frac{\\sum_{i=1}^K P@i}{K} \\]</p>\n<p>where</p>\n<p>\\[ P@i = \\frac{ \\text{#relevant - forbidden ads retrieved in the first ith places} }{i} \\]</p>\n<p>As&nbsp;Abhishek mentioned, AUC metric would already give scores of 0.99+, so&nbsp;the differences in the top leaderboard would be in the last decimal places, and chance would play a big role at the end. The chosen metric gives a little more space to improve and to differentiate between scores.</p>\n<p>[quote=&#1043;&#1077;&#1086;&#1088;&#1075;&#1080;&#1081; &#1050;&#1072;&#1083;&#1072;&#1096;&#1085;&#1086;&#1074;;50919]</p>\n<p>The author got the answer 0.782 [but]&nbsp;got answer 0.669920634921</p>\n<p>[/quote]</p>\n<p>The definition in wikipedia,</p>\n<p>\\[AP@K = \\frac{\\sum P@i * rel(i)}{\\text{# relevant at K}} \\]</p>\n<p>would also give higher scores as AUC would, so the top leaderboard would already be populated with 0.99+ scores.&nbsp;</p>\n<p>[quote=barisumog;50938]</p>\n<p>AUC takes into consideration the whole data set.</p>\n<p>[/quote]</p>\n<p>Sometimes one may not be interested&nbsp;in the&nbsp;predictions of the whole data set but only in the most confident (top) predictions.&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51079,
      "author_name": "adjgiulio",
      "author_url": "",
      "post_date": "07/23/2014 04:42:34",
      "content": "<p>How close is your CV score to LB? And do you find it directionally correct? I just started doing some CV and I find the score off by 0.008-0.016 and not always directionally correct. I'm working with k based on 5% of my test set instead of a static 32k. So far I've only used the benchmark features.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51085,
      "author_name": "barisumog",
      "author_url": "",
      "post_date": "07/23/2014 09:27:52",
      "content": "<p>[quote=Giulio;51079]</p>\n<p>I find the score off by 0.008-0.016 and not always directionally correct</p>\n<p>[/quote]</p>\n<p>More or less the&nbsp;same here.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51148,
      "author_name": "heatfanjohn",
      "author_url": "",
      "post_date": "07/24/2014 17:29:08",
      "content": "<p>[quote=Triskelion;49733]</p>\n<p><strong>Evaluating Ranked Search Engine Results</strong></p>\n<p><strong>.</strong></p>\n<p>What makes for a good search engine?</p>\n<p>.</p>\n<p>.</p>\n<p>.</p>\n<p>[/quote]</p>\n<p>Please forgive the newb question, but I take it that in the context of this competition and the information you provided on search engine performance that correctly predicting prohibited content is equivalent to relevance in search engine performance.</p>\n<p>Thank you</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51167,
      "author_name": "triskelion",
      "author_url": "",
      "post_date": "07/25/2014 06:13:19",
      "content": "<p>[quote=HeatfanJohn;51148]</p>\n<p>Please forgive the newb question, but I take it that in the context of this competition and the information you provided on search engine performance that correctly predicting prohibited content is equivalent to relevance in search engine performance.</p>\n<p>Thank you</p>\n<p>[/quote]</p>\n<p>It is much the same yes, average precision at K is a metric used in evaluating search engine relevance, and the metric in use for this competition. I suspect that Avito wants a ranked result page with illicit ads, the worst offenders on top, so moderators can act on it.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51842,
      "author_name": "chenglongchen",
      "author_url": "",
      "post_date": "08/10/2014 19:49:27",
      "content": "<p>[quote=Peter Pi&#353;ljar;50347]</p>\n<p>In case anybody will find this usefull:</p>\n<p>&nbsp;same code posted above, except that it does not read solution and predictions from the files, but keeps solution in memory, so fast evaluation is possible.</p>\n<p>[/quote]</p>\n<p>A faster implementation using cPickle and pandas :)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 52196,
      "author_name": "datanovice111981",
      "author_url": "",
      "post_date": "08/19/2014 18:22:29",
      "content": "<p>This might be a very stupid question, but I cannot figure out how to use the APatK.py file to compute a score for my solution.</p>\n<p>I understand that the predictions.csv file should be the submission file. This is the one that contains item_ids from the avito_test.tsv file, arranged in order from most illicit to least illicit content.&nbsp;</p>\n<p>However, I don't understand how to generate the solutions.tsv file.&nbsp;</p>\n\n<p>The post above says:</p>\n<p>&quot;take the submission file and eliminate all ids that are not in the 50% public</p>\n<p>take the top 32500 submitted ids from what remains</p>\n<p>count the ids that are actually spam&quot;</p>\n\n<p>Now, since the avito_test.tsv file does not mention the is_blocked parameter, how do we count the ids that are actually spam?</p>\n\n<p>Equivalently, if I look at Peter's post above, where he has attached a version of the&nbsp;APatK.py file,</p>\n<p>I don't understand how to get the&nbsp;data_test.target variable in line 6?</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "49671": "",
    "49680": "",
    "49723": "",
    "49728": "",
    "49729": "",
    "49731": "",
    "49733": "",
    "49734": "",
    "49882": "",
    "50103": "",
    "50347": "",
    "50361": "",
    "50368": "",
    "50510": "",
    "50919": "",
    "50926": "",
    "50935": "",
    "50936": "",
    "50938": "",
    "50976": "",
    "51079": "",
    "51085": "",
    "51148": "",
    "51167": "",
    "51842": "",
    "52196": ""
  },
  "source": "meta"
}