{
  "id": 21043,
  "title": "Calculating MAP in R",
  "url": "/competitions/expedia-hotel-recommendations/discussion/21043",
  "author_name": "",
  "post_date": "2016-05-18T13:47:04.513Z",
  "votes": null,
  "comment_count": 6,
  "views": 808,
  "content": "<p>Does anyone have R code for calculating mean average precision, given predicted  class probability matrix and truth value vector </p>",
  "messages": [
    {
      "id": "120465",
      "postDate": "05/18/2016 13:47:04",
      "content": "<p>Does anyone have R code for calculating mean average precision, given predicted  class probability matrix and truth value vector </p>",
      "rawMarkdown": "Does anyone have R code for calculating mean average precision, given predicted  class probability matrix and truth value vector",
      "votes": null
    },
    {
      "id": "120468",
      "postDate": "05/18/2016 14:16:38",
      "content": "<p>Hi,</p>\n\n<p>just from the evaluation page\n<a href=\"https://www.kaggle.com/wiki/MeanAveragePrecision\">https://www.kaggle.com/wiki/MeanAveragePrecision</a></p>\n\n<p><a href=\"https://github.com/benhamner/Metrics/blob/master/R/R/metrics.r#L181\">https://github.com/benhamner/Metrics/blob/master/R/R/metrics.r#L181</a></p>\n\n<p>So probably the easiest way is library(Metrics)</p>",
      "rawMarkdown": "Hi,\r\n\r\njust from the evaluation page\r\nhttps://www.kaggle.com/wiki/MeanAveragePrecision\r\n\r\nhttps://github.com/benhamner/Metrics/blob/master/R/R/metrics.r#L181\r\n\r\nSo probably the easiest way is library(Metrics)",
      "votes": null
    },
    {
      "id": "120469",
      "postDate": "05/18/2016 14:28:27",
      "content": "<p>@Justfor... I had a look on Metrics package...but inputs to mapk function are not very  clear to me... Do u have any example for it</p>",
      "rawMarkdown": "Justfor... I had a look on Metrics package...but inputs to mapk function are not very  clear to me... Do u have any example for it",
      "votes": null
    },
    {
      "id": "120474",
      "postDate": "05/18/2016 14:48:39",
      "content": "<p>From the test-cases:\n(See <a href=\"https://github.com/benhamner/Metrics/blob/master/R/inst/tests/test-apk.r\">https://github.com/benhamner/Metrics/blob/master/R/inst/tests/test-apk.r</a>)</p>\n\n<p>test.mapk &lt;- function()</p>\n\n<pre><code>{ #deleted\n\ncheckEqualsNumeric(mapk(5, list(1:5,1:5), list(c(6,4,7,1,2),c(1,1,1,1,1))), 0.26)\n}\n</code></pre>\n\n<p>See also the R-implementation from Branden Murray and the discussion the thread:\n<a href=\"https://www.kaggle.com/c/expedia-hotel-recommendations/forums/t/20556/map5-function-or-eval-metric/117749#post117749\">https://www.kaggle.com/c/expedia-hotel-recommendations/forums/t/20556/map5-function-or-eval-metric/117749#post117749</a></p>",
      "rawMarkdown": "From the test-cases:\r\n(See https://github.com/benhamner/Metrics/blob/master/R/inst/tests/test-apk.r)\r\n\r\n\r\ntest.mapk <- function()\r\n\r\n    { #deleted\r\n       \r\n    checkEqualsNumeric(mapk(5, list(1:5,1:5), list(c(6,4,7,1,2),c(1,1,1,1,1))), 0.26)\r\n    }\r\n\r\nSee also the R-implementation from Branden Murray and the discussion the thread:\r\nhttps://www.kaggle.com/c/expedia-hotel-recommendations/forums/t/20556/map5-function-or-eval-metric/117749#post117749",
      "votes": null
    },
    {
      "id": "120477",
      "postDate": "05/18/2016 14:59:13",
      "content": "<p>@justfor ...referring to \ntest.mapk &lt;- function()</p>\n\n<p>{ #deleted</p>\n\n<p>checkEqualsNumeric(mapk(5, list(1:5,1:5), list(c(6,4,7,1,2),c(1,1,1,1,1))), 0.26)\n}</p>\n\n<p>There are two list,one is list(c(6,4,7,1,2),c(1,1,1,1,1))) which is predicted list of ordered vector ...what is other list ? I am assuming other one should be a truth vector and not a list....</p>\n\n<p>Also I'm looking for a code which takes (1) predicted matrix where rows are  observations and columns are predicted ordered values ( 2) truth target value vector ....</p>\n\n<p>Branden Murray implementation is again in turn using mapk which is Ben Hammer implementation ... And its not clear to me about inputs to mapk... </p>",
      "rawMarkdown": "justfor ...referring to \r\ntest.mapk <- function()\r\n\r\n{ #deleted\r\n\r\ncheckEqualsNumeric(mapk(5, list(1:5,1:5), list(c(6,4,7,1,2),c(1,1,1,1,1))), 0.26)\r\n}\r\n\r\nThere are two list,one is list(c(6,4,7,1,2),c(1,1,1,1,1))) which is predicted list of ordered vector ...what is other list ? I am assuming other one should be a truth vector and not a list....\r\n\r\nAlso I'm looking for a code which takes (1) predicted matrix where rows are  observations and columns are predicted ordered values ( 2) truth target value vector ....\r\n\r\nBranden Murray implementation is again in turn using mapk which is Ben Hammer implementation ... And its not clear to me about inputs to mapk...",
      "votes": null
    },
    {
      "id": "120483",
      "postDate": "05/18/2016 15:42:42",
      "content": "<p>first,  convert  predicted_matrix into a list: </p>\n\n<p>predicted_list &lt;- as.list(as.data.frame(t(predicted_matrix))) , or</p>\n\n<p>predicted_list  &lt;- split(predicted_matrix, seq(nrow(predicted_matrix)))</p>\n\n<p>Then, mapk(5, truth_target_value_vector, predicted_list)</p>",
      "rawMarkdown": "first,  convert  predicted_matrix into a list: \r\n\r\n predicted_list <- as.list(as.data.frame(t(predicted_matrix))) , or\r\n\r\npredicted_list  <- split(predicted_matrix, seq(nrow(predicted_matrix)))\r\n\r\nThen, mapk(5, truth_target_value_vector, predicted_list)",
      "votes": null
    },
    {
      "id": "120489",
      "postDate": "05/18/2016 16:24:52",
      "content": "<p>@minimalist.... I think ....that should work...thank u.. :-) </p>",
      "rawMarkdown": "minimalist.... I think ....that should work...thank u.. :-)",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 120468,
      "author_name": "justfor",
      "author_url": "",
      "post_date": "05/18/2016 14:16:38",
      "content": "<p>Hi,</p>\n\n<p>just from the evaluation page\n<a href=\"https://www.kaggle.com/wiki/MeanAveragePrecision\">https://www.kaggle.com/wiki/MeanAveragePrecision</a></p>\n\n<p><a href=\"https://github.com/benhamner/Metrics/blob/master/R/R/metrics.r#L181\">https://github.com/benhamner/Metrics/blob/master/R/R/metrics.r#L181</a></p>\n\n<p>So probably the easiest way is library(Metrics)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 120469,
      "author_name": "arpangupta87",
      "author_url": "",
      "post_date": "05/18/2016 14:28:27",
      "content": "<p>@Justfor... I had a look on Metrics package...but inputs to mapk function are not very  clear to me... Do u have any example for it</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 120474,
      "author_name": "justfor",
      "author_url": "",
      "post_date": "05/18/2016 14:48:39",
      "content": "<p>From the test-cases:\n(See <a href=\"https://github.com/benhamner/Metrics/blob/master/R/inst/tests/test-apk.r\">https://github.com/benhamner/Metrics/blob/master/R/inst/tests/test-apk.r</a>)</p>\n\n<p>test.mapk &lt;- function()</p>\n\n<pre><code>{ #deleted\n\ncheckEqualsNumeric(mapk(5, list(1:5,1:5), list(c(6,4,7,1,2),c(1,1,1,1,1))), 0.26)\n}\n</code></pre>\n\n<p>See also the R-implementation from Branden Murray and the discussion the thread:\n<a href=\"https://www.kaggle.com/c/expedia-hotel-recommendations/forums/t/20556/map5-function-or-eval-metric/117749#post117749\">https://www.kaggle.com/c/expedia-hotel-recommendations/forums/t/20556/map5-function-or-eval-metric/117749#post117749</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 120477,
      "author_name": "arpangupta87",
      "author_url": "",
      "post_date": "05/18/2016 14:59:13",
      "content": "<p>@justfor ...referring to \ntest.mapk &lt;- function()</p>\n\n<p>{ #deleted</p>\n\n<p>checkEqualsNumeric(mapk(5, list(1:5,1:5), list(c(6,4,7,1,2),c(1,1,1,1,1))), 0.26)\n}</p>\n\n<p>There are two list,one is list(c(6,4,7,1,2),c(1,1,1,1,1))) which is predicted list of ordered vector ...what is other list ? I am assuming other one should be a truth vector and not a list....</p>\n\n<p>Also I'm looking for a code which takes (1) predicted matrix where rows are  observations and columns are predicted ordered values ( 2) truth target value vector ....</p>\n\n<p>Branden Murray implementation is again in turn using mapk which is Ben Hammer implementation ... And its not clear to me about inputs to mapk... </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 120483,
      "author_name": "trenqualye",
      "author_url": "",
      "post_date": "05/18/2016 15:42:42",
      "content": "<p>first,  convert  predicted_matrix into a list: </p>\n\n<p>predicted_list &lt;- as.list(as.data.frame(t(predicted_matrix))) , or</p>\n\n<p>predicted_list  &lt;- split(predicted_matrix, seq(nrow(predicted_matrix)))</p>\n\n<p>Then, mapk(5, truth_target_value_vector, predicted_list)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 120489,
      "author_name": "arpangupta87",
      "author_url": "",
      "post_date": "05/18/2016 16:24:52",
      "content": "<p>@minimalist.... I think ....that should work...thank u.. :-) </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "120465": "Does anyone have R code for calculating mean average precision, given predicted  class probability matrix and truth value vector",
    "120468": "Hi,\r\n\r\njust from the evaluation page\r\nhttps://www.kaggle.com/wiki/MeanAveragePrecision\r\n\r\nhttps://github.com/benhamner/Metrics/blob/master/R/R/metrics.r#L181\r\n\r\nSo probably the easiest way is library(Metrics)",
    "120469": "Justfor... I had a look on Metrics package...but inputs to mapk function are not very  clear to me... Do u have any example for it",
    "120474": "From the test-cases:\r\n(See https://github.com/benhamner/Metrics/blob/master/R/inst/tests/test-apk.r)\r\n\r\n\r\ntest.mapk <- function()\r\n\r\n    { #deleted\r\n       \r\n    checkEqualsNumeric(mapk(5, list(1:5,1:5), list(c(6,4,7,1,2),c(1,1,1,1,1))), 0.26)\r\n    }\r\n\r\nSee also the R-implementation from Branden Murray and the discussion the thread:\r\nhttps://www.kaggle.com/c/expedia-hotel-recommendations/forums/t/20556/map5-function-or-eval-metric/117749#post117749",
    "120477": "justfor ...referring to \r\ntest.mapk <- function()\r\n\r\n{ #deleted\r\n\r\ncheckEqualsNumeric(mapk(5, list(1:5,1:5), list(c(6,4,7,1,2),c(1,1,1,1,1))), 0.26)\r\n}\r\n\r\nThere are two list,one is list(c(6,4,7,1,2),c(1,1,1,1,1))) which is predicted list of ordered vector ...what is other list ? I am assuming other one should be a truth vector and not a list....\r\n\r\nAlso I'm looking for a code which takes (1) predicted matrix where rows are  observations and columns are predicted ordered values ( 2) truth target value vector ....\r\n\r\nBranden Murray implementation is again in turn using mapk which is Ben Hammer implementation ... And its not clear to me about inputs to mapk...",
    "120483": "first,  convert  predicted_matrix into a list: \r\n\r\n predicted_list <- as.list(as.data.frame(t(predicted_matrix))) , or\r\n\r\npredicted_list  <- split(predicted_matrix, seq(nrow(predicted_matrix)))\r\n\r\nThen, mapk(5, truth_target_value_vector, predicted_list)",
    "120489": "minimalist.... I think ....that should work...thank u.. :-)"
  },
  "source": "meta"
}