{
  "id": 291845,
  "title": "Evaluation Metric Clarification",
  "url": "/competitions/g-research-crypto-forecasting/discussion/291845",
  "author_name": "Kieran Garvey",
  "post_date": "2021-12-01T07:39:54.924000",
  "votes": 60,
  "comment_count": 19,
  "views": 0,
  "content": "<p>Hi Kagglers,</p>\n<p>We would like to clarify how the evaluation metric has been calculated to address your related questions.</p>\n<p>The evaluation metric is weighted correlation as opposed to a weighted mean of correlation. </p>\n<p>The metric is defined as follows, where 'a', 'b' and 'weights' are vectors of the same length. </p>\n<p>'a' and 'b' are the expected and predicted targets, and ' weights' include the weight of each row, determined by its asset:</p>\n<pre><code>def weighted_correlation(a, b, weights):\n\n  w = np.ravel(weights)\n  a = np.ravel(a)\n  b = np.ravel(b)\n\n  sum_w = np.sum(w)\n  mean_a = np.sum(a * w) / sum_w\n  mean_b = np.sum(b * w) / sum_w\n  var_a = np.sum(w * np.square(a - mean_a)) / sum_w\n  var_b = np.sum(w * np.square(b - mean_b)) / sum_w\n\n  cov = np.sum((a * b * w)) / np.sum(w) - mean_a * mean_b\n  corr = cov / np.sqrt(var_a * var_b)\n\n  return corr\n</code></pre>\n<p>Thanks and happy Kaggling!</p>",
  "messages": [
    {
      "id": 1601355,
      "postDate": "2021-12-01T07:39:54.923Z",
      "content": "<p>Hi Kagglers,</p>\n<p>We would like to clarify how the evaluation metric has been calculated to address your related questions.</p>\n<p>The evaluation metric is weighted correlation as opposed to a weighted mean of correlation. </p>\n<p>The metric is defined as follows, where 'a', 'b' and 'weights' are vectors of the same length. </p>\n<p>'a' and 'b' are the expected and predicted targets, and ' weights' include the weight of each row, determined by its asset:</p>\n<pre><code>def weighted_correlation(a, b, weights):\n\n  w = np.ravel(weights)\n  a = np.ravel(a)\n  b = np.ravel(b)\n\n  sum_w = np.sum(w)\n  mean_a = np.sum(a * w) / sum_w\n  mean_b = np.sum(b * w) / sum_w\n  var_a = np.sum(w * np.square(a - mean_a)) / sum_w\n  var_b = np.sum(w * np.square(b - mean_b)) / sum_w\n\n  cov = np.sum((a * b * w)) / np.sum(w) - mean_a * mean_b\n  corr = cov / np.sqrt(var_a * var_b)\n\n  return corr\n</code></pre>\n<p>Thanks and happy Kaggling!</p>",
      "rawMarkdown": "Hi Kagglers,\n\nWe would like to clarify how the evaluation metric has been calculated to address your related questions.\n\nThe evaluation metric is weighted correlation as opposed to a weighted mean of correlation. \n\nThe metric is defined as follows, where 'a', 'b' and 'weights' are vectors of the same length. \n\n'a' and 'b' are the expected and predicted targets, and ' weights' include the weight of each row, determined by its asset:\n\n```\ndef weighted_correlation(a, b, weights):\n\n  w = np.ravel(weights)\n  a = np.ravel(a)\n  b = np.ravel(b)\n\n  sum_w = np.sum(w)\n  mean_a = np.sum(a * w) / sum_w\n  mean_b = np.sum(b * w) / sum_w\n  var_a = np.sum(w * np.square(a - mean_a)) / sum_w\n  var_b = np.sum(w * np.square(b - mean_b)) / sum_w\n\n  cov = np.sum((a * b * w)) / np.sum(w) - mean_a * mean_b\n  corr = cov / np.sqrt(var_a * var_b)\n\n  return corr\n```\n\nThanks and happy Kaggling!\n",
      "votes": 59
    },
    {
      "id": 1615082,
      "postDate": "2021-12-11T19:31:40.797Z",
      "content": "<p>Isn't it the \"Pearson correlation coefficient\" - <code>scipy.stats.pearsonr</code>?</p>",
      "rawMarkdown": "Isn't it the \"Pearson correlation coefficient\" - `scipy.stats.pearsonr`?",
      "votes": 1
    },
    {
      "id": 1602832,
      "postDate": "2021-12-02T06:53:07.230Z",
      "content": "<p><a href=\"https://www.kaggle.com/kierangarvey\" target=\"_blank\">@kierangarvey</a>, Thanks for the info. I suppose that if the targets are NAN, are not included in the calculation.</p>\n<p>It seems that it is clear now.</p>",
      "rawMarkdown": "@kierangarvey, Thanks for the info. I suppose that if the targets are NAN, are not included in the calculation.\n\nIt seems that it is clear now.",
      "votes": 1
    },
    {
      "id": 1668049,
      "postDate": "2022-01-29T08:43:30.703Z",
      "content": "<p>Is not the mean of x, for example, is : sum(x)/n , where n = len(x)</p>\n<p>and then if values in x are weighted by another vector w, then it becomes:</p>\n<p>sum(x*w) / sum_w / n</p>\n<p>where sum_w = sum(w), and sum(w/sum_w) = 1</p>\n<p>If so, then the calculation of mean_a &amp; mean_b should be like  </p>\n<p>mean_a = np.sum(a * w) / sum_w / <strong>n</strong><br>\nmean_b = np.sum(b * w) / sum_w / <strong>n</strong></p>\n<p>where n = len(a) = len(b) = len(w)</p>",
      "rawMarkdown": "Is not the mean of x, for example, is : sum(x)/n , where n = len(x)\n\nand then if values in x are weighted by another vector w, then it becomes:\n\nsum(x*w) / sum_w / n\n\nwhere sum_w = sum(w), and sum(w/sum_w) = 1\n\nIf so, then the calculation of mean_a & mean_b should be like  \n\nmean_a = np.sum(a * w) / sum_w / **n**\nmean_b = np.sum(b * w) / sum_w / **n**\n\nwhere n = len(a) = len(b) = len(w)"
    },
    {
      "id": 1653795,
      "postDate": "2022-01-17T21:36:13.590Z",
      "content": "<p>très merci à vous!</p>",
      "rawMarkdown": "très merci à vous!"
    },
    {
      "id": 1603203,
      "postDate": "2021-12-02T11:51:36.903Z",
      "content": "<p>Pretty sure it does not work i measured the metric between the volume feature and the overlapped targets <a href=\"https://www.kaggle.com/swaralipibose/metric\" target=\"_blank\">https://www.kaggle.com/swaralipibose/metric</a> here is the code for that and also submitted it got different score the code is here <a href=\"https://www.kaggle.com/swaralipibose/detailed-api-introduction-300351\" target=\"_blank\">https://www.kaggle.com/swaralipibose/detailed-api-introduction-300351</a> I might be wrong either </p>",
      "rawMarkdown": "Pretty sure it does not work i measured the metric between the volume feature and the overlapped targets https://www.kaggle.com/swaralipibose/metric here is the code for that and also submitted it got different score the code is here https://www.kaggle.com/swaralipibose/detailed-api-introduction-300351 I might be wrong either ",
      "replies": [
        {
          "id": 1603398,
          "postDate": "2021-12-02T13:49:05.900Z",
          "content": "<p><a href=\"https://www.kaggle.com/swaralipibose\" target=\"_blank\">@swaralipibose</a> ,</p>\n<p>Why do you use the correlation between Volume and Target?</p>\n<blockquote>\n  <p>weighted_correlation(test['Volume'],public_lb['Target'],test['Weight'])</p>\n</blockquote>\n<p>maybe you should use the target, no?</p>",
          "rawMarkdown": "@swaralipibose ,\n\nWhy do you use the correlation between Volume and Target?\n\n>weighted_correlation(test['Volume'],public_lb['Target'],test['Weight'])\n\nmaybe you should use the target, no?"
        },
        {
          "id": 1603400,
          "postDate": "2021-12-02T13:50:37.330Z",
          "content": "<p>This is just for example <a href=\"https://www.kaggle.com/agenlu\" target=\"_blank\">@agenlu</a> just like random useless predictions but it does not matter as I am just comparing here</p>",
          "rawMarkdown": "This is just for example @agenlu just like random useless predictions but it does not matter as I am just comparing here"
        },
        {
          "id": 1603571,
          "postDate": "2021-12-02T15:23:46.233Z",
          "content": "<p><a href=\"https://www.kaggle.com/swaralipibose\" target=\"_blank\">@swaralipibose</a>, sorry, I didn’t read all your comment. Maybe the problem is that example_test doesn’t include all the public_lb</p>",
          "rawMarkdown": "@swaralipibose, sorry, I didn’t read all your comment. Maybe the problem is that example_test doesn’t include all the public_lb"
        },
        {
          "id": 1604934,
          "postDate": "2021-12-03T21:21:35.783Z",
          "rawMarkdown": "",
          "isDeleted": true
        },
        {
          "id": 1605401,
          "postDate": "2021-12-04T07:32:22.093Z",
          "content": "<p><a href=\"https://www.kaggle.com/dmk2021\" target=\"_blank\">@dmk2021</a>, read this:</p>\n<p><a href=\"https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/290265\" target=\"_blank\">https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/290265</a></p>\n<p>public LB is included in the train data.</p>",
          "rawMarkdown": "@dmk2021, read this:\n\n[https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/290265](https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/290265)\n\npublic LB is included in the train data.\n"
        },
        {
          "id": 1611459,
          "postDate": "2021-12-08T01:58:18.133Z",
          "rawMarkdown": "",
          "isDeleted": true
        },
        {
          "id": 1611806,
          "postDate": "2021-12-08T09:33:05.283Z",
          "content": "<p><a href=\"https://www.kaggle.com/dmk2021\" target=\"_blank\">@dmk2021</a>, example_test doesn’t include all the data in the public lb, is just an example on how the test data is going to be.</p>\n<p>As I have pointed out in the above link post, the public leaderboard has the train rows above 2021-06-13. So, if you want to make your experiments you need to cut the train data, as explained in the above post.</p>\n<p>Read this:</p>\n<p><a href=\"https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/290265\" target=\"_blank\">https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/290265</a></p>",
          "rawMarkdown": "@dmk2021, example_test doesn’t include all the data in the public lb, is just an example on how the test data is going to be.\n\nAs I have pointed out in the above link post, the public leaderboard has the train rows above 2021-06-13. So, if you want to make your experiments you need to cut the train data, as explained in the above post.\n\nRead this:\n\n\n[https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/290265](https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/290265)\n"
        },
        {
          "id": 1612098,
          "postDate": "2021-12-08T14:49:10Z",
          "rawMarkdown": "",
          "votes": 3,
          "isDeleted": true
        },
        {
          "id": 1612519,
          "postDate": "2021-12-09T03:45:38.457Z",
          "content": "<p>Interesting </p>",
          "rawMarkdown": "Interesting "
        },
        {
          "id": 1613154,
          "postDate": "2021-12-09T17:06:55.203Z",
          "rawMarkdown": "",
          "votes": 2,
          "isDeleted": true
        },
        {
          "id": 1652492,
          "postDate": "2022-01-16T17:20:48.463Z",
          "content": "<p>yes, would be nice to have this clarified. Why are the organizers so secretive of this weight? They can just publish the code which calculates the weights.</p>",
          "rawMarkdown": "yes, would be nice to have this clarified. Why are the organizers so secretive of this weight? They can just publish the code which calculates the weights."
        }
      ]
    },
    {
      "id": 1641296,
      "postDate": "2022-01-07T09:20:18.567Z",
      "rawMarkdown": "",
      "isDeleted": true
    },
    {
      "id": 1612357,
      "postDate": "2021-12-08T19:51:22.567Z",
      "content": "<p>Thanks for the explanation!</p>",
      "rawMarkdown": "Thanks for the explanation!",
      "votes": 1
    },
    {
      "id": 1611955,
      "postDate": "2021-12-08T12:19:05.020Z",
      "content": "<p>Thanks for your explanation.<br>\nThx</p>",
      "rawMarkdown": "Thanks for your explanation.\nThx~~~~~",
      "votes": 1
    }
  ],
  "comments": [
    {
      "id": 1615082,
      "author_name": "Mark Babayev",
      "author_url": "",
      "post_date": "2021-12-11T19:31:40.797000",
      "content": "<p>Isn't it the \"Pearson correlation coefficient\" - <code>scipy.stats.pearsonr</code>?</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1602832,
      "author_name": "agenlu",
      "author_url": "",
      "post_date": "2021-12-02T06:53:07.230000",
      "content": "<p><a href=\"https://www.kaggle.com/kierangarvey\" target=\"_blank\">@kierangarvey</a>, Thanks for the info. I suppose that if the targets are NAN, are not included in the calculation.</p>\n<p>It seems that it is clear now.</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1668049,
      "author_name": "Mohammad Tarek",
      "author_url": "",
      "post_date": "2022-01-29T08:43:30.703000",
      "content": "<p>Is not the mean of x, for example, is : sum(x)/n , where n = len(x)</p>\n<p>and then if values in x are weighted by another vector w, then it becomes:</p>\n<p>sum(x*w) / sum_w / n</p>\n<p>where sum_w = sum(w), and sum(w/sum_w) = 1</p>\n<p>If so, then the calculation of mean_a &amp; mean_b should be like  </p>\n<p>mean_a = np.sum(a * w) / sum_w / <strong>n</strong><br>\nmean_b = np.sum(b * w) / sum_w / <strong>n</strong></p>\n<p>where n = len(a) = len(b) = len(w)</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1653795,
      "author_name": "Hansheng LIANG",
      "author_url": "",
      "post_date": "2022-01-17T21:36:13.590000",
      "content": "<p>très merci à vous!</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1603203,
      "author_name": "Sayantan Mazumdar",
      "author_url": "",
      "post_date": "2021-12-02T11:51:36.903000",
      "content": "<p>Pretty sure it does not work i measured the metric between the volume feature and the overlapped targets <a href=\"https://www.kaggle.com/swaralipibose/metric\" target=\"_blank\">https://www.kaggle.com/swaralipibose/metric</a> here is the code for that and also submitted it got different score the code is here <a href=\"https://www.kaggle.com/swaralipibose/detailed-api-introduction-300351\" target=\"_blank\">https://www.kaggle.com/swaralipibose/detailed-api-introduction-300351</a> I might be wrong either </p>",
      "votes": 0,
      "replies": [
        {
          "id": 1603398,
          "author_name": "agenlu",
          "author_url": "",
          "post_date": "2021-12-02T13:49:05.900000",
          "content": "<p><a href=\"https://www.kaggle.com/swaralipibose\" target=\"_blank\">@swaralipibose</a> ,</p>\n<p>Why do you use the correlation between Volume and Target?</p>\n<blockquote>\n  <p>weighted_correlation(test['Volume'],public_lb['Target'],test['Weight'])</p>\n</blockquote>\n<p>maybe you should use the target, no?</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1603400,
          "author_name": "Sayantan Mazumdar",
          "author_url": "",
          "post_date": "2021-12-02T13:50:37.330000",
          "content": "<p>This is just for example <a href=\"https://www.kaggle.com/agenlu\" target=\"_blank\">@agenlu</a> just like random useless predictions but it does not matter as I am just comparing here</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1603571,
          "author_name": "agenlu",
          "author_url": "",
          "post_date": "2021-12-02T15:23:46.233000",
          "content": "<p><a href=\"https://www.kaggle.com/swaralipibose\" target=\"_blank\">@swaralipibose</a>, sorry, I didn’t read all your comment. Maybe the problem is that example_test doesn’t include all the public_lb</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1604934,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-12-03T21:21:35.783000",
          "content": "",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1605401,
          "author_name": "agenlu",
          "author_url": "",
          "post_date": "2021-12-04T07:32:22.093000",
          "content": "<p><a href=\"https://www.kaggle.com/dmk2021\" target=\"_blank\">@dmk2021</a>, read this:</p>\n<p><a href=\"https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/290265\" target=\"_blank\">https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/290265</a></p>\n<p>public LB is included in the train data.</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1611459,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-12-08T01:58:18.133000",
          "content": "",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1611806,
          "author_name": "agenlu",
          "author_url": "",
          "post_date": "2021-12-08T09:33:05.283000",
          "content": "<p><a href=\"https://www.kaggle.com/dmk2021\" target=\"_blank\">@dmk2021</a>, example_test doesn’t include all the data in the public lb, is just an example on how the test data is going to be.</p>\n<p>As I have pointed out in the above link post, the public leaderboard has the train rows above 2021-06-13. So, if you want to make your experiments you need to cut the train data, as explained in the above post.</p>\n<p>Read this:</p>\n<p><a href=\"https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/290265\" target=\"_blank\">https://www.kaggle.com/c/g-research-crypto-forecasting/discussion/290265</a></p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1612098,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-12-08T14:49:10",
          "content": "",
          "votes": 3,
          "replies": []
        },
        {
          "id": 1612519,
          "author_name": "Sayantan Mazumdar",
          "author_url": "",
          "post_date": "2021-12-09T03:45:38.457000",
          "content": "<p>Interesting </p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1613154,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-12-09T17:06:55.203000",
          "content": "",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1652492,
          "author_name": "Endre Moen",
          "author_url": "",
          "post_date": "2022-01-16T17:20:48.463000",
          "content": "<p>yes, would be nice to have this clarified. Why are the organizers so secretive of this weight? They can just publish the code which calculates the weights.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1641296,
      "author_name": "",
      "author_url": "",
      "post_date": "2022-01-07T09:20:18.567000",
      "content": "",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1612357,
      "author_name": "JONALLDAY",
      "author_url": "",
      "post_date": "2021-12-08T19:51:22.567000",
      "content": "<p>Thanks for the explanation!</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1611955,
      "author_name": "Hongkai WANG",
      "author_url": "",
      "post_date": "2021-12-08T12:19:05.020000",
      "content": "<p>Thanks for your explanation.<br>\nThx</p>",
      "votes": 1,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1601355": "Hi Kagglers,\n\nWe would like to clarify how the evaluation metric has been calculated to address your related questions.\n\nThe evaluation metric is weighted correlation as opposed to a weighted mean of correlation. \n\nThe metric is defined as follows, where 'a', 'b' and 'weights' are vectors of the same length. \n\n'a' and 'b' are the expected and predicted targets, and ' weights' include the weight of each row, determined by its asset:\n\n```\ndef weighted_correlation(a, b, weights):\n\n  w = np.ravel(weights)\n  a = np.ravel(a)\n  b = np.ravel(b)\n\n  sum_w = np.sum(w)\n  mean_a = np.sum(a * w) / sum_w\n  mean_b = np.sum(b * w) / sum_w\n  var_a = np.sum(w * np.square(a - mean_a)) / sum_w\n  var_b = np.sum(w * np.square(b - mean_b)) / sum_w\n\n  cov = np.sum((a * b * w)) / np.sum(w) - mean_a * mean_b\n  corr = cov / np.sqrt(var_a * var_b)\n\n  return corr\n```\n\nThanks and happy Kaggling!\n",
    "1615082": "Isn't it the \"Pearson correlation coefficient\" - `scipy.stats.pearsonr`?",
    "1602832": "@kierangarvey, Thanks for the info. I suppose that if the targets are NAN, are not included in the calculation.\n\nIt seems that it is clear now.",
    "1668049": "Is not the mean of x, for example, is : sum(x)/n , where n = len(x)\n\nand then if values in x are weighted by another vector w, then it becomes:\n\nsum(x*w) / sum_w / n\n\nwhere sum_w = sum(w), and sum(w/sum_w) = 1\n\nIf so, then the calculation of mean_a & mean_b should be like  \n\nmean_a = np.sum(a * w) / sum_w / **n**\nmean_b = np.sum(b * w) / sum_w / **n**\n\nwhere n = len(a) = len(b) = len(w)",
    "1653795": "très merci à vous!",
    "1603203": "Pretty sure it does not work i measured the metric between the volume feature and the overlapped targets https://www.kaggle.com/swaralipibose/metric here is the code for that and also submitted it got different score the code is here https://www.kaggle.com/swaralipibose/detailed-api-introduction-300351 I might be wrong either ",
    "1641296": "",
    "1612357": "Thanks for the explanation!",
    "1611955": "Thanks for your explanation.\nThx~~~~~"
  }
}