{
  "id": 205225,
  "title": "LRAP with an example",
  "url": "/competitions/rfcx-species-audio-detection/discussion/205225",
  "author_name": "",
  "post_date": "2020-12-19T04:33:30.956365700Z",
  "votes": 4,
  "comment_count": 2,
  "views": 0,
  "content": "<p>If anyone trying to understand why LRAP for this comp. The following example will give a better picture:</p>\n<p>y_true = np.array([[1, 0, 0],  <br>\n                   [1, 0, 1],  <br>\n                   [1, 1, 0]]) <br>\ny_score = np.array([[0.75, 0.5, 1],  <br>\n                    [1, 0.2, 0.1], <br>\n                    [0.9, 0.7, 0.6]]) </p>\n<p>To understand above example, Let’s take three categories human (represented by [1, 0, 0]), cat(represented by [0, 1, 0]), dog(represented by [0, 0, 1]). We were provided three samples such as [1, 0, 0], [1, 0, 1], [1, 1, 0] . This means we have total number of 5 ground truth labels (3 of humans, 1 of cat and 1 of dog). In the first sample for example, only true label human got 2nd place in prediction label. so, rank = 2. Next we need to find out how many correct labels along the way. There is only one correct label that is human so the numerator value is 1. Hence the fraction becomes 1/2 = 0.5.<br>\nTherefore, the LRAP value of 1st sample is:</p>\n<p><img src=\"https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-bc01e6abafb955a7c9ab668472e1f7d9_l3.svg\" alt=\"\"></p>\n<p>In the second sample, the first rank prediction is of human, followed by cat and dog. The fraction for the human is 1/1 = 1 and the dog is 2/3 = 0.66 (number of true label ranking along the way/ranking of dog class in the predicted label).<br>\nLRAP value of 2nd sample is:</p>\n<p><img src=\"https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-525e5e4da527b0e31f734a5b4326132a_l3.svg\" alt=\"\"></p>\n<p>Similarly, for the third sample, the value of fractions for the human class is 1/1 = 1 and the cat class is 2/2 = 1. LRAP value of 3rd sample is:</p>\n<p><img src=\"https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-23153fe592b65cd4d60b75336cdf1499_l3.svg\" alt=\"\"></p>\n<p>Therefore total LRAP is the sum of LRAP’s on each sample divided by the number of samples.</p>\n<p><img src=\"https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-3e5db9e38ae3fe824770421e312b435f_l3.svg\" alt=\"\"></p>\n<p>Link ref:<br>\n<a href=\"https://www.geeksforgeeks.org/multilabel-ranking-metrics-label-ranking-average-precision-ml/\" target=\"_blank\">https://www.geeksforgeeks.org/multilabel-ranking-metrics-label-ranking-average-precision-ml/</a></p>",
  "messages": [
    {
      "id": "1118442",
      "postDate": "12/19/2020 04:33:30",
      "content": "<p>If anyone trying to understand why LRAP for this comp. The following example will give a better picture:</p>\n<p>y_true = np.array([[1, 0, 0],  <br>\n                   [1, 0, 1],  <br>\n                   [1, 1, 0]]) <br>\ny_score = np.array([[0.75, 0.5, 1],  <br>\n                    [1, 0.2, 0.1], <br>\n                    [0.9, 0.7, 0.6]]) </p>\n<p>To understand above example, Let’s take three categories human (represented by [1, 0, 0]), cat(represented by [0, 1, 0]), dog(represented by [0, 0, 1]). We were provided three samples such as [1, 0, 0], [1, 0, 1], [1, 1, 0] . This means we have total number of 5 ground truth labels (3 of humans, 1 of cat and 1 of dog). In the first sample for example, only true label human got 2nd place in prediction label. so, rank = 2. Next we need to find out how many correct labels along the way. There is only one correct label that is human so the numerator value is 1. Hence the fraction becomes 1/2 = 0.5.<br>\nTherefore, the LRAP value of 1st sample is:</p>\n<p><img src=\"https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-bc01e6abafb955a7c9ab668472e1f7d9_l3.svg\" alt=\"\"></p>\n<p>In the second sample, the first rank prediction is of human, followed by cat and dog. The fraction for the human is 1/1 = 1 and the dog is 2/3 = 0.66 (number of true label ranking along the way/ranking of dog class in the predicted label).<br>\nLRAP value of 2nd sample is:</p>\n<p><img src=\"https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-525e5e4da527b0e31f734a5b4326132a_l3.svg\" alt=\"\"></p>\n<p>Similarly, for the third sample, the value of fractions for the human class is 1/1 = 1 and the cat class is 2/2 = 1. LRAP value of 3rd sample is:</p>\n<p><img src=\"https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-23153fe592b65cd4d60b75336cdf1499_l3.svg\" alt=\"\"></p>\n<p>Therefore total LRAP is the sum of LRAP’s on each sample divided by the number of samples.</p>\n<p><img src=\"https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-3e5db9e38ae3fe824770421e312b435f_l3.svg\" alt=\"\"></p>\n<p>Link ref:<br>\n<a href=\"https://www.geeksforgeeks.org/multilabel-ranking-metrics-label-ranking-average-precision-ml/\" target=\"_blank\">https://www.geeksforgeeks.org/multilabel-ranking-metrics-label-ranking-average-precision-ml/</a></p>",
      "rawMarkdown": "If anyone trying to understand why LRAP for this comp. The following example will give a better picture:\n\ny_true = np.array([[1, 0, 0],  \n                   [1, 0, 1],  \n                   [1, 1, 0]]) \ny_score = np.array([[0.75, 0.5, 1],  \n                    [1, 0.2, 0.1], \n                    [0.9, 0.7, 0.6]]) \n\nTo understand above example, Let’s take three categories human (represented by [1, 0, 0]), cat(represented by [0, 1, 0]), dog(represented by [0, 0, 1]). We were provided three samples such as [1, 0, 0], [1, 0, 1], [1, 1, 0] . This means we have total number of 5 ground truth labels (3 of humans, 1 of cat and 1 of dog). In the first sample for example, only true label human got 2nd place in prediction label. so, rank = 2. Next we need to find out how many correct labels along the way. There is only one correct label that is human so the numerator value is 1. Hence the fraction becomes 1/2 = 0.5.\nTherefore, the LRAP value of 1st sample is:\n\n![](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-bc01e6abafb955a7c9ab668472e1f7d9_l3.svg)\n\nIn the second sample, the first rank prediction is of human, followed by cat and dog. The fraction for the human is 1/1 = 1 and the dog is 2/3 = 0.66 (number of true label ranking along the way/ranking of dog class in the predicted label).\nLRAP value of 2nd sample is:\n\n ![](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-525e5e4da527b0e31f734a5b4326132a_l3.svg)\n\nSimilarly, for the third sample, the value of fractions for the human class is 1/1 = 1 and the cat class is 2/2 = 1. LRAP value of 3rd sample is:\n\n ![](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-23153fe592b65cd4d60b75336cdf1499_l3.svg)\n\n\nTherefore total LRAP is the sum of LRAP’s on each sample divided by the number of samples.\n\n![](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-3e5db9e38ae3fe824770421e312b435f_l3.svg)\n\n\nLink ref:\nhttps://www.geeksforgeeks.org/multilabel-ranking-metrics-label-ranking-average-precision-ml/",
      "votes": null
    },
    {
      "id": "1118792",
      "postDate": "12/19/2020 12:03:01",
      "content": "<p>Thanks for sharing. Looks like you forgot example per se :) It's difficult to understand clarifications w/o y_score…</p>",
      "rawMarkdown": "Thanks for sharing. Looks like you forgot example per se :) It's difficult to understand clarifications w/o y_score...",
      "votes": null
    },
    {
      "id": "1118811",
      "postDate": "12/19/2020 12:21:06",
      "content": "<p>Thanks…Updated! <a href=\"https://www.kaggle.com/egm108\" target=\"_blank\">@egm108</a> </p>",
      "rawMarkdown": "Thanks...Updated! @egm108",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1118792,
      "author_name": "egm108",
      "author_url": "",
      "post_date": "12/19/2020 12:03:01",
      "content": "<p>Thanks for sharing. Looks like you forgot example per se :) It's difficult to understand clarifications w/o y_score…</p>",
      "votes": null,
      "replies": [
        {
          "id": 1118811,
          "author_name": "nandhuelan",
          "author_url": "",
          "post_date": "12/19/2020 12:21:06",
          "content": "<p>Thanks…Updated! <a href=\"https://www.kaggle.com/egm108\" target=\"_blank\">@egm108</a> </p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1118442": "If anyone trying to understand why LRAP for this comp. The following example will give a better picture:\n\ny_true = np.array([[1, 0, 0],  \n                   [1, 0, 1],  \n                   [1, 1, 0]]) \ny_score = np.array([[0.75, 0.5, 1],  \n                    [1, 0.2, 0.1], \n                    [0.9, 0.7, 0.6]]) \n\nTo understand above example, Let’s take three categories human (represented by [1, 0, 0]), cat(represented by [0, 1, 0]), dog(represented by [0, 0, 1]). We were provided three samples such as [1, 0, 0], [1, 0, 1], [1, 1, 0] . This means we have total number of 5 ground truth labels (3 of humans, 1 of cat and 1 of dog). In the first sample for example, only true label human got 2nd place in prediction label. so, rank = 2. Next we need to find out how many correct labels along the way. There is only one correct label that is human so the numerator value is 1. Hence the fraction becomes 1/2 = 0.5.\nTherefore, the LRAP value of 1st sample is:\n\n![](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-bc01e6abafb955a7c9ab668472e1f7d9_l3.svg)\n\nIn the second sample, the first rank prediction is of human, followed by cat and dog. The fraction for the human is 1/1 = 1 and the dog is 2/3 = 0.66 (number of true label ranking along the way/ranking of dog class in the predicted label).\nLRAP value of 2nd sample is:\n\n ![](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-525e5e4da527b0e31f734a5b4326132a_l3.svg)\n\nSimilarly, for the third sample, the value of fractions for the human class is 1/1 = 1 and the cat class is 2/2 = 1. LRAP value of 3rd sample is:\n\n ![](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-23153fe592b65cd4d60b75336cdf1499_l3.svg)\n\n\nTherefore total LRAP is the sum of LRAP’s on each sample divided by the number of samples.\n\n![](https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-3e5db9e38ae3fe824770421e312b435f_l3.svg)\n\n\nLink ref:\nhttps://www.geeksforgeeks.org/multilabel-ranking-metrics-label-ranking-average-precision-ml/",
    "1118792": "Thanks for sharing. Looks like you forgot example per se :) It's difficult to understand clarifications w/o y_score...",
    "1118811": "Thanks...Updated! @egm108"
  },
  "source": "meta"
}