{
  "id": 323703,
  "title": "3rd place solution",
  "url": "/competitions/g-research-crypto-forecasting/discussion/323703",
  "author_name": "sugghi",
  "post_date": "2022-05-07T22:19:32.173000",
  "votes": 67,
  "comment_count": 30,
  "views": 0,
  "content": "<p>First of all, I would like to thank G-Research, kaggle and all competitors. I have learned a lot through this interesting competition. It was very difficult for me (actually, it was the third machine learning challenge in my life) and without the knowledge shared by all the kagglers, I would not have been able to handle it.</p>\n<p>Also, since this is a competition with a strong element of luck, it was only by sheer luck that I was able to finish in third place, but I am glad that my rank was somewhat stable in the last few updates.</p>\n<p>In coding, I referred to the knowledge of kagglers. I am especially grateful to <a href=\"https://www.kaggle.com/jagofc\" target=\"_blank\">@jagofc</a> for providing <a href=\"https://www.kaggle.com/code/jagofc/local-api/\" target=\"_blank\">local api</a>. Without <a href=\"https://www.kaggle.com/jagofc\" target=\"_blank\">@jagofc</a>'s local api, I would not have been able to successfully submit even once.</p>\n<p>Here is my solution. If you have any suggestions for improvement or anything else you think I should know, I'd be glad to hear from you!</p>\n<p>The link to the notebook is as follows;</p>\n<ul>\n<li>training: <a href=\"https://www.kaggle.com/code/sugghi/training-3rd-place-solution\" target=\"_blank\">https://www.kaggle.com/code/sugghi/training-3rd-place-solution</a></li>\n<li>inference: <a href=\"https://www.kaggle.com/code/sugghi/inference-3rd-place-solution\" target=\"_blank\">https://www.kaggle.com/code/sugghi/inference-3rd-place-solution</a></li>\n</ul>\n<h3>Overview of my model</h3>\n<p>The characteristics of my model are as follows</p>\n<ul>\n<li>Only 'Close' is used.</li>\n<li>The model is trained for each coin using a common set of features for all the coins.</li>\n<li>The difference between the change of each currency and the change of all currencies is provided as features.</li>\n<li>Single model of LightGBM (7-fold CV)</li>\n</ul>\n<p>Considering the definition of the forecasting target in this competition, I felt it was necessary to prepare features with information about the entire market. I also thought that some currencies might be affected by the movements of other currencies, so I made it possible to refer to information about other currencies as well. Since I thought that memory and inference time would become more demanding with this kind of processing, I reduced the amount of data to be used. Specifically, I considered 'Close', which is used to calculate the target, to be the most important, so I decided to use only it. Even so, the ensemble could not be performed because of the limited inference time (and lack of coding skill).</p>\n<p>For CV, I used <a href=\"https://www.kaggle.com/code/nrcjea001/lgbm-embargocv-weightedpearson-lagtarget/\" target=\"_blank\">EmbargoCV</a> by <a href=\"https://www.kaggle.com/nrcjea001\" target=\"_blank\">@nrcjea001</a>.</p>\n<h3>About the data used for training</h3>\n<p>The start date of train data differed greatly among currencies. Since my model deals with the average of the changes of each currency, I considered it undesirable for the existing currencies to differ significantly between the training period and the evaluation period. As I expected that all currencies would have few missing values during the evaluation period of the competition, I decided not to use all of the train data, but to use the data from the period when there were enough currencies present.</p>\n<p>The selection of the starting date was done by looking at the CV scores. However, this was a mistake in hindsight, since it meant that I was comparing CV scores across different data.</p>\n<p>Also, each currency had several long and short blank periods. I attempted forward fill to prevent missing data as a result of rolling. On the other hand, I thought that forward fill for the entire period might cause a decline in data quality when there is a long blank period, so I set a limit on forward fill. In the evaluation phase, the code was designed to have forward fill without a limit, but I thought this would not be a problem since there are no long blank periods in the evaluation phase.</p>\n<h3>Feature engineering</h3>\n<p>Since the value of cryptocurrencies is increasing, I tried to make sure to pick up the magnitude of the change independent of the evaluation period.</p>\n<p>For 'Close', I prepared two features for multiple lag periods: the log of the ratio of the current value to the average during the period, and the log of the ratio of the current value to the value a certain period ago. For these, I took the average for all currencies (Due to missing data, no weighted averaging was performed). In addition, the difference between each currency and the average of all currencies was also prepared as a feature. As a result, this feature seems to have worked well.</p>\n<h3>Dealing with time limit</h3>\n<p>The most difficult part for me was the time limit. When inference is performed, it should be sufficient to generate only one row of features, but my programming skills did not allow me to do this well, so I gave up on this and generated features for all data. So, I tried to avoid using pandas as much as possible to speed up the process, and managed to finish the inference within 9 hours. To be honest, I was quite worried about the timeout at the final update.</p>\n<h3>What I would have worked on if I had more time</h3>\n<ul>\n<li>Speed up feature generation to save time and perform ensemble.</li>\n<li>Learning with less missing data (external data?)</li>\n<li>Parameter optimization<br>\nThe first successful submission was a week before the end of the competition, so I have not been able to optimize much.</li>\n</ul>\n<p>I would like to continue to improve so that I can achieve results in competitions where the element of luck is small. See you at the next competition!</p>",
  "messages": [
    {
      "id": 1780797,
      "postDate": "2022-05-07T22:19:32.173Z",
      "content": "<p>First of all, I would like to thank G-Research, kaggle and all competitors. I have learned a lot through this interesting competition. It was very difficult for me (actually, it was the third machine learning challenge in my life) and without the knowledge shared by all the kagglers, I would not have been able to handle it.</p>\n<p>Also, since this is a competition with a strong element of luck, it was only by sheer luck that I was able to finish in third place, but I am glad that my rank was somewhat stable in the last few updates.</p>\n<p>In coding, I referred to the knowledge of kagglers. I am especially grateful to <a href=\"https://www.kaggle.com/jagofc\" target=\"_blank\">@jagofc</a> for providing <a href=\"https://www.kaggle.com/code/jagofc/local-api/\" target=\"_blank\">local api</a>. Without <a href=\"https://www.kaggle.com/jagofc\" target=\"_blank\">@jagofc</a>'s local api, I would not have been able to successfully submit even once.</p>\n<p>Here is my solution. If you have any suggestions for improvement or anything else you think I should know, I'd be glad to hear from you!</p>\n<p>The link to the notebook is as follows;</p>\n<ul>\n<li>training: <a href=\"https://www.kaggle.com/code/sugghi/training-3rd-place-solution\" target=\"_blank\">https://www.kaggle.com/code/sugghi/training-3rd-place-solution</a></li>\n<li>inference: <a href=\"https://www.kaggle.com/code/sugghi/inference-3rd-place-solution\" target=\"_blank\">https://www.kaggle.com/code/sugghi/inference-3rd-place-solution</a></li>\n</ul>\n<h3>Overview of my model</h3>\n<p>The characteristics of my model are as follows</p>\n<ul>\n<li>Only 'Close' is used.</li>\n<li>The model is trained for each coin using a common set of features for all the coins.</li>\n<li>The difference between the change of each currency and the change of all currencies is provided as features.</li>\n<li>Single model of LightGBM (7-fold CV)</li>\n</ul>\n<p>Considering the definition of the forecasting target in this competition, I felt it was necessary to prepare features with information about the entire market. I also thought that some currencies might be affected by the movements of other currencies, so I made it possible to refer to information about other currencies as well. Since I thought that memory and inference time would become more demanding with this kind of processing, I reduced the amount of data to be used. Specifically, I considered 'Close', which is used to calculate the target, to be the most important, so I decided to use only it. Even so, the ensemble could not be performed because of the limited inference time (and lack of coding skill).</p>\n<p>For CV, I used <a href=\"https://www.kaggle.com/code/nrcjea001/lgbm-embargocv-weightedpearson-lagtarget/\" target=\"_blank\">EmbargoCV</a> by <a href=\"https://www.kaggle.com/nrcjea001\" target=\"_blank\">@nrcjea001</a>.</p>\n<h3>About the data used for training</h3>\n<p>The start date of train data differed greatly among currencies. Since my model deals with the average of the changes of each currency, I considered it undesirable for the existing currencies to differ significantly between the training period and the evaluation period. As I expected that all currencies would have few missing values during the evaluation period of the competition, I decided not to use all of the train data, but to use the data from the period when there were enough currencies present.</p>\n<p>The selection of the starting date was done by looking at the CV scores. However, this was a mistake in hindsight, since it meant that I was comparing CV scores across different data.</p>\n<p>Also, each currency had several long and short blank periods. I attempted forward fill to prevent missing data as a result of rolling. On the other hand, I thought that forward fill for the entire period might cause a decline in data quality when there is a long blank period, so I set a limit on forward fill. In the evaluation phase, the code was designed to have forward fill without a limit, but I thought this would not be a problem since there are no long blank periods in the evaluation phase.</p>\n<h3>Feature engineering</h3>\n<p>Since the value of cryptocurrencies is increasing, I tried to make sure to pick up the magnitude of the change independent of the evaluation period.</p>\n<p>For 'Close', I prepared two features for multiple lag periods: the log of the ratio of the current value to the average during the period, and the log of the ratio of the current value to the value a certain period ago. For these, I took the average for all currencies (Due to missing data, no weighted averaging was performed). In addition, the difference between each currency and the average of all currencies was also prepared as a feature. As a result, this feature seems to have worked well.</p>\n<h3>Dealing with time limit</h3>\n<p>The most difficult part for me was the time limit. When inference is performed, it should be sufficient to generate only one row of features, but my programming skills did not allow me to do this well, so I gave up on this and generated features for all data. So, I tried to avoid using pandas as much as possible to speed up the process, and managed to finish the inference within 9 hours. To be honest, I was quite worried about the timeout at the final update.</p>\n<h3>What I would have worked on if I had more time</h3>\n<ul>\n<li>Speed up feature generation to save time and perform ensemble.</li>\n<li>Learning with less missing data (external data?)</li>\n<li>Parameter optimization<br>\nThe first successful submission was a week before the end of the competition, so I have not been able to optimize much.</li>\n</ul>\n<p>I would like to continue to improve so that I can achieve results in competitions where the element of luck is small. See you at the next competition!</p>",
      "rawMarkdown": "First of all, I would like to thank G-Research, kaggle and all competitors. I have learned a lot through this interesting competition. It was very difficult for me (actually, it was the third machine learning challenge in my life) and without the knowledge shared by all the kagglers, I would not have been able to handle it.\n\nAlso, since this is a competition with a strong element of luck, it was only by sheer luck that I was able to finish in third place, but I am glad that my rank was somewhat stable in the last few updates.\n\nIn coding, I referred to the knowledge of kagglers. I am especially grateful to @jagofc for providing [local api](https://www.kaggle.com/code/jagofc/local-api/). Without @jagofc's local api, I would not have been able to successfully submit even once.\n\nHere is my solution. If you have any suggestions for improvement or anything else you think I should know, I'd be glad to hear from you!\n\nThe link to the notebook is as follows;\n- training: https://www.kaggle.com/code/sugghi/training-3rd-place-solution\n- inference: https://www.kaggle.com/code/sugghi/inference-3rd-place-solution\n\n\n### Overview of my model\nThe characteristics of my model are as follows\n- Only 'Close' is used.\n- The model is trained for each coin using a common set of features for all the coins.\n- The difference between the change of each currency and the change of all currencies is provided as features.\n- Single model of LightGBM (7-fold CV)\n\nConsidering the definition of the forecasting target in this competition, I felt it was necessary to prepare features with information about the entire market. I also thought that some currencies might be affected by the movements of other currencies, so I made it possible to refer to information about other currencies as well. Since I thought that memory and inference time would become more demanding with this kind of processing, I reduced the amount of data to be used. Specifically, I considered 'Close', which is used to calculate the target, to be the most important, so I decided to use only it. Even so, the ensemble could not be performed because of the limited inference time (and lack of coding skill).\n\nFor CV, I used [EmbargoCV](https://www.kaggle.com/code/nrcjea001/lgbm-embargocv-weightedpearson-lagtarget/) by @nrcjea001.\n\n\n### About the data used for training\nThe start date of train data differed greatly among currencies. Since my model deals with the average of the changes of each currency, I considered it undesirable for the existing currencies to differ significantly between the training period and the evaluation period. As I expected that all currencies would have few missing values during the evaluation period of the competition, I decided not to use all of the train data, but to use the data from the period when there were enough currencies present.\n\nThe selection of the starting date was done by looking at the CV scores. However, this was a mistake in hindsight, since it meant that I was comparing CV scores across different data.\n\nAlso, each currency had several long and short blank periods. I attempted forward fill to prevent missing data as a result of rolling. On the other hand, I thought that forward fill for the entire period might cause a decline in data quality when there is a long blank period, so I set a limit on forward fill. In the evaluation phase, the code was designed to have forward fill without a limit, but I thought this would not be a problem since there are no long blank periods in the evaluation phase.\n\n\n### Feature engineering\nSince the value of cryptocurrencies is increasing, I tried to make sure to pick up the magnitude of the change independent of the evaluation period.\n\nFor 'Close', I prepared two features for multiple lag periods: the log of the ratio of the current value to the average during the period, and the log of the ratio of the current value to the value a certain period ago. For these, I took the average for all currencies (Due to missing data, no weighted averaging was performed). In addition, the difference between each currency and the average of all currencies was also prepared as a feature. As a result, this feature seems to have worked well.\n\n\n### Dealing with time limit\nThe most difficult part for me was the time limit. When inference is performed, it should be sufficient to generate only one row of features, but my programming skills did not allow me to do this well, so I gave up on this and generated features for all data. So, I tried to avoid using pandas as much as possible to speed up the process, and managed to finish the inference within 9 hours. To be honest, I was quite worried about the timeout at the final update.\n\n\n### What I would have worked on if I had more time\n- Speed up feature generation to save time and perform ensemble.\n- Learning with less missing data (external data?)\n- Parameter optimization\nThe first successful submission was a week before the end of the competition, so I have not been able to optimize much.\n\n\n\nI would like to continue to improve so that I can achieve results in competitions where the element of luck is small. See you at the next competition!",
      "votes": 66
    },
    {
      "id": 1781438,
      "postDate": "2022-05-08T13:53:30.053Z",
      "content": "<p><a href=\"https://www.kaggle.com/sugghi\" target=\"_blank\">@sugghi</a> Many congratulations! And thank you for mentioning the local_api - I'm very glad it was useful :)</p>",
      "rawMarkdown": "@sugghi Many congratulations! And thank you for mentioning the local_api - I'm very glad it was useful :)",
      "votes": 4,
      "replies": [
        {
          "id": 1781524,
          "postDate": "2022-05-08T15:28:24.563Z",
          "content": "<p>I greatly appreciate your local_api!<br>\nThank you once again!</p>",
          "rawMarkdown": "I greatly appreciate your local_api!\nThank you once again!",
          "votes": 1
        },
        {
          "id": 1782428,
          "postDate": "2022-05-09T15:19:13.780Z",
          "content": "<p>I used your API as well, <a href=\"https://www.kaggle.com/jagofc\" target=\"_blank\">@jagofc</a>, and forgot to mention it. Thank you.</p>",
          "rawMarkdown": "I used your API as well, @jagofc, and forgot to mention it. Thank you.",
          "votes": 2
        },
        {
          "id": 1782480,
          "postDate": "2022-05-09T16:01:07.113Z",
          "content": "<p>Haha, you're welcome <a href=\"https://www.kaggle.com/nathanrm\" target=\"_blank\">@nathanrm</a>! I wonder if Meme Lord Capital did too… :D</p>",
          "rawMarkdown": "Haha, you're welcome @nathanrm! I wonder if Meme Lord Capital did too... :D",
          "votes": 1
        }
      ]
    },
    {
      "id": 1997720,
      "postDate": "2022-10-21T05:58:47.987Z",
      "content": "<p>In your feature engineering code in training, can you explain the following line of code -</p>\n<blockquote>\n  <p>df[f'log_close/mean_{lag}<em>id{id}'] = np.log( np.array(df[f'Close</em>{id}']) /  np.roll(np.append(np.convolve( np.array(df[f'Close_{id}']), np.ones(lag)/lag, mode=\"valid\"), np.ones(lag-1)), lag-1)  )</p>\n</blockquote>\n<p>Thanks for your wonderful solution!</p>",
      "rawMarkdown": "In your feature engineering code in training, can you explain the following line of code -\n\n> df[f'log_close/mean_{lag}_id{id}'] = np.log( np.array(df[f'Close_{id}']) /  np.roll(np.append(np.convolve( np.array(df[f'Close_{id}']), np.ones(lag)/lag, mode=\"valid\"), np.ones(lag-1)), lag-1)  )\n\nThanks for your wonderful solution!",
      "votes": 2,
      "replies": [
        {
          "id": 1997864,
          "postDate": "2022-10-21T07:52:35.373Z",
          "content": "<p>Thanks for your question.</p>\n<p>I used such confusing code to avoid using pandas to accelerate inference.<br>\nThe original and simpler code was as follows;<br>\n<code>df[f'log_close/mean_{lag}_id{id}'] = np.log( df[f'Close_{id}'] / df[f'Close_{id}'].rolling(lag).mean() )</code></p>",
          "rawMarkdown": "Thanks for your question.\n\nI used such confusing code to avoid using pandas to accelerate inference.\nThe original and simpler code was as follows;\n`df[f'log_close/mean_{lag}_id{id}'] = np.log( df[f'Close_{id}'] / df[f'Close_{id}'].rolling(lag).mean() )`",
          "votes": 4,
          "replies": [
            {
              "id": 2923401,
              "postDate": "2024-07-15T21:01:12.857Z",
              "content": "<p>Stumbled upon this, doesn't your numpy version introduce a bug? roll != shift, as roll will not introduce NaNs but instead roll values from the end of the array to the front.</p>",
              "rawMarkdown": "Stumbled upon this, doesn't your numpy version introduce a bug? roll != shift, as roll will not introduce NaNs but instead roll values from the end of the array to the front.",
              "votes": 1
            },
            {
              "id": 3094235,
              "postDate": "2025-01-11T19:18:16.750Z",
              "rawMarkdown": "",
              "isDeleted": true
            },
            {
              "id": 3094237,
              "postDate": "2025-01-11T19:19:10.323Z",
              "content": "<p>Yes, the first |lag| values will use the last |lag| values 🫤</p>",
              "rawMarkdown": "Yes, the first |lag| values will use the last |lag| values 🫤"
            }
          ]
        }
      ]
    },
    {
      "id": 1821809,
      "postDate": "2022-06-15T21:04:45.660Z",
      "content": "<p>Great solution and thanks for sharing the code…!! 🙌🙌</p>\n<p>I downloaded, implemented and run it, but I still dont understand it… :( </p>\n<p>Could someone helpme to study this code or tellme where to begin?? (my email is: oblitasss@hotmail.com) I really read the code and the info of this contest… </p>",
      "rawMarkdown": "Great solution and thanks for sharing the code...!! 🙌🙌\n\nI downloaded, implemented and run it, but I still dont understand it... :( \n\nCould someone helpme to study this code or tellme where to begin?? (my email is: oblitasss@hotmail.com) I really read the code and the info of this contest... ",
      "votes": 1
    },
    {
      "id": 1782900,
      "postDate": "2022-05-10T01:37:17.197Z",
      "content": "<p>Congratulations on your achievement, and many thanks for sharing your work! </p>",
      "rawMarkdown": "Congratulations on your achievement, and many thanks for sharing your work! ",
      "votes": 1
    },
    {
      "id": 1782025,
      "postDate": "2022-05-09T07:01:33.387Z",
      "content": "<p>Nice share!</p>",
      "rawMarkdown": "Nice share!",
      "votes": 1
    },
    {
      "id": 1781930,
      "postDate": "2022-05-09T05:11:53.800Z",
      "content": "<p><a href=\"https://www.kaggle.com/sugghi\" target=\"_blank\">@sugghi</a> Congratulations on 3rd! 🎉 Thanks for sharing your work and approach; very insightful.</p>",
      "rawMarkdown": "@sugghi Congratulations on 3rd! 🎉 Thanks for sharing your work and approach; very insightful.",
      "votes": 1,
      "replies": [
        {
          "id": 1782005,
          "postDate": "2022-05-09T06:39:43.013Z",
          "content": "<p>Thank you for celebrating!</p>",
          "rawMarkdown": "Thank you for celebrating!",
          "votes": 1
        }
      ]
    },
    {
      "id": 1781868,
      "postDate": "2022-05-09T03:47:41.360Z",
      "content": "<p>very good one</p>",
      "rawMarkdown": "very good one",
      "votes": 1,
      "replies": [
        {
          "id": 1782002,
          "postDate": "2022-05-09T06:37:31.703Z",
          "content": "<p>Thanks for your comment!</p>",
          "rawMarkdown": "Thanks for your comment!"
        }
      ]
    },
    {
      "id": 1780979,
      "postDate": "2022-05-08T05:10:46.990Z",
      "content": "<p>Thank you for the mention :)</p>",
      "rawMarkdown": "Thank you for the mention :)",
      "votes": 1,
      "replies": [
        {
          "id": 1781504,
          "postDate": "2022-05-08T15:17:20.287Z",
          "content": "<p>I have greatly benefited from your code. Thank you!</p>",
          "rawMarkdown": "I have greatly benefited from your code. Thank you!",
          "votes": 2
        }
      ]
    },
    {
      "id": 1780895,
      "postDate": "2022-05-08T02:21:13.093Z",
      "content": "<p>Congratulations on winning the gold medal 🎉💯<br>\nAlso, thanks for sharing the training code with us.</p>\n<p>I' ll learn about your model. <br>\nI look forward to seeing you again at the finance competition 😃</p>",
      "rawMarkdown": "Congratulations on winning the gold medal 🎉💯\nAlso, thanks for sharing the training code with us.\n\nI' ll learn about your model. \nI look forward to seeing you again at the finance competition 😃",
      "votes": 1,
      "replies": [
        {
          "id": 1781500,
          "postDate": "2022-05-08T15:15:26.273Z",
          "content": "<p>Thank you for celebrating with me!<br>\nI look forward to competing in another competition!</p>",
          "rawMarkdown": "Thank you for celebrating with me!\nI look forward to competing in another competition!",
          "votes": 1
        }
      ]
    },
    {
      "id": 1780840,
      "postDate": "2022-05-07T23:53:26.280Z",
      "content": "<p><a href=\"https://www.kaggle.com/sugghi\" target=\"_blank\">@sugghi</a> thanks for this post! I learned some valuable things reading through the feature engineering section :)</p>",
      "rawMarkdown": "@sugghi thanks for this post! I learned some valuable things reading through the feature engineering section :)",
      "votes": 1,
      "replies": [
        {
          "id": 1781495,
          "postDate": "2022-05-08T15:10:28.993Z",
          "content": "<p>Thanks for your comment!<br>\nI am glad you found it useful :)</p>",
          "rawMarkdown": "Thanks for your comment!\nI am glad you found it useful :)"
        }
      ]
    },
    {
      "id": 1781655,
      "postDate": "2022-05-08T19:11:55.390Z",
      "content": "<p>Congratulations <a href=\"https://www.kaggle.com/sugghi…very\" target=\"_blank\">@sugghi…very</a> well done! Thanks for sharing the notebooks. Hope to learn some feature engineering aspects. Wish you the best for other competitions.</p>",
      "rawMarkdown": "Congratulations @sugghi...very well done! Thanks for sharing the notebooks. Hope to learn some feature engineering aspects. Wish you the best for other competitions.",
      "votes": 2,
      "replies": [
        {
          "id": 1782001,
          "postDate": "2022-05-09T06:36:41.173Z",
          "content": "<p>Thanks for your message! I am glad you found it useful!</p>",
          "rawMarkdown": "Thanks for your message! I am glad you found it useful!"
        }
      ]
    },
    {
      "id": 1781209,
      "postDate": "2022-05-08T09:51:33.080Z",
      "content": "<p>Yay for Feature Engineering and lgbm ! Also many thanks for sharing the whole code :)</p>",
      "rawMarkdown": "Yay for Feature Engineering and lgbm ! Also many thanks for sharing the whole code :)",
      "votes": 2,
      "replies": [
        {
          "id": 1781515,
          "postDate": "2022-05-08T15:24:14.170Z",
          "content": "<p>Thanks for your comment!<br>\nI hope my code is helpful :)</p>",
          "rawMarkdown": "Thanks for your comment!\nI hope my code is helpful :)"
        }
      ]
    },
    {
      "id": 1800466,
      "postDate": "2022-05-25T01:51:27.697Z",
      "rawMarkdown": "",
      "isDeleted": true
    },
    {
      "id": 1785952,
      "postDate": "2022-05-12T14:10:54.643Z",
      "rawMarkdown": "",
      "votes": 1,
      "isDeleted": true
    },
    {
      "id": 1793885,
      "postDate": "2022-05-18T10:03:50.460Z",
      "content": "<p>thanks for sharing!</p>",
      "rawMarkdown": "thanks for sharing!",
      "votes": 1
    },
    {
      "id": 2193716,
      "postDate": "2023-03-23T12:45:06.177Z",
      "content": "<p>thanks a lot for sharing your code,</p>",
      "rawMarkdown": "thanks a lot for sharing your code,"
    }
  ],
  "comments": [
    {
      "id": 1781438,
      "author_name": "jagofc",
      "author_url": "",
      "post_date": "2022-05-08T13:53:30.053000",
      "content": "<p><a href=\"https://www.kaggle.com/sugghi\" target=\"_blank\">@sugghi</a> Many congratulations! And thank you for mentioning the local_api - I'm very glad it was useful :)</p>",
      "votes": 4,
      "replies": [
        {
          "id": 1781524,
          "author_name": "sugghi",
          "author_url": "",
          "post_date": "2022-05-08T15:28:24.563000",
          "content": "<p>I greatly appreciate your local_api!<br>\nThank you once again!</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1782428,
          "author_name": "Nathaniel Maddux",
          "author_url": "",
          "post_date": "2022-05-09T15:19:13.780000",
          "content": "<p>I used your API as well, <a href=\"https://www.kaggle.com/jagofc\" target=\"_blank\">@jagofc</a>, and forgot to mention it. Thank you.</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1782480,
          "author_name": "jagofc",
          "author_url": "",
          "post_date": "2022-05-09T16:01:07.113000",
          "content": "<p>Haha, you're welcome <a href=\"https://www.kaggle.com/nathanrm\" target=\"_blank\">@nathanrm</a>! I wonder if Meme Lord Capital did too… :D</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1997720,
      "author_name": "theDoors",
      "author_url": "",
      "post_date": "2022-10-21T05:58:47.987000",
      "content": "<p>In your feature engineering code in training, can you explain the following line of code -</p>\n<blockquote>\n  <p>df[f'log_close/mean_{lag}<em>id{id}'] = np.log( np.array(df[f'Close</em>{id}']) /  np.roll(np.append(np.convolve( np.array(df[f'Close_{id}']), np.ones(lag)/lag, mode=\"valid\"), np.ones(lag-1)), lag-1)  )</p>\n</blockquote>\n<p>Thanks for your wonderful solution!</p>",
      "votes": 2,
      "replies": [
        {
          "id": 1997864,
          "author_name": "sugghi",
          "author_url": "",
          "post_date": "2022-10-21T07:52:35.373000",
          "content": "<p>Thanks for your question.</p>\n<p>I used such confusing code to avoid using pandas to accelerate inference.<br>\nThe original and simpler code was as follows;<br>\n<code>df[f'log_close/mean_{lag}_id{id}'] = np.log( df[f'Close_{id}'] / df[f'Close_{id}'].rolling(lag).mean() )</code></p>",
          "votes": 4,
          "replies": [
            {
              "id": 2923401,
              "author_name": "Volgoesupndown",
              "author_url": "",
              "post_date": "2024-07-15T21:01:12.857000",
              "content": "<p>Stumbled upon this, doesn't your numpy version introduce a bug? roll != shift, as roll will not introduce NaNs but instead roll values from the end of the array to the front.</p>",
              "votes": 1,
              "replies": []
            },
            {
              "id": 3094235,
              "author_name": "",
              "author_url": "",
              "post_date": "2025-01-11T19:18:16.750000",
              "content": "",
              "votes": 0,
              "replies": []
            },
            {
              "id": 3094237,
              "author_name": "T!",
              "author_url": "",
              "post_date": "2025-01-11T19:19:10.323000",
              "content": "<p>Yes, the first |lag| values will use the last |lag| values 🫤</p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 1821809,
      "author_name": "Carlos Oblitas Villegas",
      "author_url": "",
      "post_date": "2022-06-15T21:04:45.660000",
      "content": "<p>Great solution and thanks for sharing the code…!! 🙌🙌</p>\n<p>I downloaded, implemented and run it, but I still dont understand it… :( </p>\n<p>Could someone helpme to study this code or tellme where to begin?? (my email is: oblitasss@hotmail.com) I really read the code and the info of this contest… </p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1782900,
      "author_name": "PosixHouse",
      "author_url": "",
      "post_date": "2022-05-10T01:37:17.197000",
      "content": "<p>Congratulations on your achievement, and many thanks for sharing your work! </p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1782025,
      "author_name": "Arthur Hsu",
      "author_url": "",
      "post_date": "2022-05-09T07:01:33.387000",
      "content": "<p>Nice share!</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1781930,
      "author_name": "Niek van der Zwaag",
      "author_url": "",
      "post_date": "2022-05-09T05:11:53.800000",
      "content": "<p><a href=\"https://www.kaggle.com/sugghi\" target=\"_blank\">@sugghi</a> Congratulations on 3rd! 🎉 Thanks for sharing your work and approach; very insightful.</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1782005,
          "author_name": "sugghi",
          "author_url": "",
          "post_date": "2022-05-09T06:39:43.013000",
          "content": "<p>Thank you for celebrating!</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1781868,
      "author_name": "Aditya sinha",
      "author_url": "",
      "post_date": "2022-05-09T03:47:41.360000",
      "content": "<p>very good one</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1782002,
          "author_name": "sugghi",
          "author_url": "",
          "post_date": "2022-05-09T06:37:31.703000",
          "content": "<p>Thanks for your comment!</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1780979,
      "author_name": "Jean-Michel Nairac",
      "author_url": "",
      "post_date": "2022-05-08T05:10:46.990000",
      "content": "<p>Thank you for the mention :)</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1781504,
          "author_name": "sugghi",
          "author_url": "",
          "post_date": "2022-05-08T15:17:20.287000",
          "content": "<p>I have greatly benefited from your code. Thank you!</p>",
          "votes": 2,
          "replies": []
        }
      ]
    },
    {
      "id": 1780895,
      "author_name": "Never$",
      "author_url": "",
      "post_date": "2022-05-08T02:21:13.093000",
      "content": "<p>Congratulations on winning the gold medal 🎉💯<br>\nAlso, thanks for sharing the training code with us.</p>\n<p>I' ll learn about your model. <br>\nI look forward to seeing you again at the finance competition 😃</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1781500,
          "author_name": "sugghi",
          "author_url": "",
          "post_date": "2022-05-08T15:15:26.273000",
          "content": "<p>Thank you for celebrating with me!<br>\nI look forward to competing in another competition!</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1780840,
      "author_name": "Lachlan Gillian",
      "author_url": "",
      "post_date": "2022-05-07T23:53:26.280000",
      "content": "<p><a href=\"https://www.kaggle.com/sugghi\" target=\"_blank\">@sugghi</a> thanks for this post! I learned some valuable things reading through the feature engineering section :)</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1781495,
          "author_name": "sugghi",
          "author_url": "",
          "post_date": "2022-05-08T15:10:28.993000",
          "content": "<p>Thanks for your comment!<br>\nI am glad you found it useful :)</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1781655,
      "author_name": "Viji",
      "author_url": "",
      "post_date": "2022-05-08T19:11:55.390000",
      "content": "<p>Congratulations <a href=\"https://www.kaggle.com/sugghi…very\" target=\"_blank\">@sugghi…very</a> well done! Thanks for sharing the notebooks. Hope to learn some feature engineering aspects. Wish you the best for other competitions.</p>",
      "votes": 2,
      "replies": [
        {
          "id": 1782001,
          "author_name": "sugghi",
          "author_url": "",
          "post_date": "2022-05-09T06:36:41.173000",
          "content": "<p>Thanks for your message! I am glad you found it useful!</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1781209,
      "author_name": "Lucas Morin",
      "author_url": "",
      "post_date": "2022-05-08T09:51:33.080000",
      "content": "<p>Yay for Feature Engineering and lgbm ! Also many thanks for sharing the whole code :)</p>",
      "votes": 2,
      "replies": [
        {
          "id": 1781515,
          "author_name": "sugghi",
          "author_url": "",
          "post_date": "2022-05-08T15:24:14.170000",
          "content": "<p>Thanks for your comment!<br>\nI hope my code is helpful :)</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1800466,
      "author_name": "",
      "author_url": "",
      "post_date": "2022-05-25T01:51:27.697000",
      "content": "",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1785952,
      "author_name": "",
      "author_url": "",
      "post_date": "2022-05-12T14:10:54.643000",
      "content": "",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1793885,
      "author_name": "yuanzhe zhou",
      "author_url": "",
      "post_date": "2022-05-18T10:03:50.460000",
      "content": "<p>thanks for sharing!</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 2193716,
      "author_name": "julinChou",
      "author_url": "",
      "post_date": "2023-03-23T12:45:06.177000",
      "content": "<p>thanks a lot for sharing your code,</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1780797": "First of all, I would like to thank G-Research, kaggle and all competitors. I have learned a lot through this interesting competition. It was very difficult for me (actually, it was the third machine learning challenge in my life) and without the knowledge shared by all the kagglers, I would not have been able to handle it.\n\nAlso, since this is a competition with a strong element of luck, it was only by sheer luck that I was able to finish in third place, but I am glad that my rank was somewhat stable in the last few updates.\n\nIn coding, I referred to the knowledge of kagglers. I am especially grateful to @jagofc for providing [local api](https://www.kaggle.com/code/jagofc/local-api/). Without @jagofc's local api, I would not have been able to successfully submit even once.\n\nHere is my solution. If you have any suggestions for improvement or anything else you think I should know, I'd be glad to hear from you!\n\nThe link to the notebook is as follows;\n- training: https://www.kaggle.com/code/sugghi/training-3rd-place-solution\n- inference: https://www.kaggle.com/code/sugghi/inference-3rd-place-solution\n\n\n### Overview of my model\nThe characteristics of my model are as follows\n- Only 'Close' is used.\n- The model is trained for each coin using a common set of features for all the coins.\n- The difference between the change of each currency and the change of all currencies is provided as features.\n- Single model of LightGBM (7-fold CV)\n\nConsidering the definition of the forecasting target in this competition, I felt it was necessary to prepare features with information about the entire market. I also thought that some currencies might be affected by the movements of other currencies, so I made it possible to refer to information about other currencies as well. Since I thought that memory and inference time would become more demanding with this kind of processing, I reduced the amount of data to be used. Specifically, I considered 'Close', which is used to calculate the target, to be the most important, so I decided to use only it. Even so, the ensemble could not be performed because of the limited inference time (and lack of coding skill).\n\nFor CV, I used [EmbargoCV](https://www.kaggle.com/code/nrcjea001/lgbm-embargocv-weightedpearson-lagtarget/) by @nrcjea001.\n\n\n### About the data used for training\nThe start date of train data differed greatly among currencies. Since my model deals with the average of the changes of each currency, I considered it undesirable for the existing currencies to differ significantly between the training period and the evaluation period. As I expected that all currencies would have few missing values during the evaluation period of the competition, I decided not to use all of the train data, but to use the data from the period when there were enough currencies present.\n\nThe selection of the starting date was done by looking at the CV scores. However, this was a mistake in hindsight, since it meant that I was comparing CV scores across different data.\n\nAlso, each currency had several long and short blank periods. I attempted forward fill to prevent missing data as a result of rolling. On the other hand, I thought that forward fill for the entire period might cause a decline in data quality when there is a long blank period, so I set a limit on forward fill. In the evaluation phase, the code was designed to have forward fill without a limit, but I thought this would not be a problem since there are no long blank periods in the evaluation phase.\n\n\n### Feature engineering\nSince the value of cryptocurrencies is increasing, I tried to make sure to pick up the magnitude of the change independent of the evaluation period.\n\nFor 'Close', I prepared two features for multiple lag periods: the log of the ratio of the current value to the average during the period, and the log of the ratio of the current value to the value a certain period ago. For these, I took the average for all currencies (Due to missing data, no weighted averaging was performed). In addition, the difference between each currency and the average of all currencies was also prepared as a feature. As a result, this feature seems to have worked well.\n\n\n### Dealing with time limit\nThe most difficult part for me was the time limit. When inference is performed, it should be sufficient to generate only one row of features, but my programming skills did not allow me to do this well, so I gave up on this and generated features for all data. So, I tried to avoid using pandas as much as possible to speed up the process, and managed to finish the inference within 9 hours. To be honest, I was quite worried about the timeout at the final update.\n\n\n### What I would have worked on if I had more time\n- Speed up feature generation to save time and perform ensemble.\n- Learning with less missing data (external data?)\n- Parameter optimization\nThe first successful submission was a week before the end of the competition, so I have not been able to optimize much.\n\n\n\nI would like to continue to improve so that I can achieve results in competitions where the element of luck is small. See you at the next competition!",
    "1781438": "@sugghi Many congratulations! And thank you for mentioning the local_api - I'm very glad it was useful :)",
    "1997720": "In your feature engineering code in training, can you explain the following line of code -\n\n> df[f'log_close/mean_{lag}_id{id}'] = np.log( np.array(df[f'Close_{id}']) /  np.roll(np.append(np.convolve( np.array(df[f'Close_{id}']), np.ones(lag)/lag, mode=\"valid\"), np.ones(lag-1)), lag-1)  )\n\nThanks for your wonderful solution!",
    "1821809": "Great solution and thanks for sharing the code...!! 🙌🙌\n\nI downloaded, implemented and run it, but I still dont understand it... :( \n\nCould someone helpme to study this code or tellme where to begin?? (my email is: oblitasss@hotmail.com) I really read the code and the info of this contest... ",
    "1782900": "Congratulations on your achievement, and many thanks for sharing your work! ",
    "1782025": "Nice share!",
    "1781930": "@sugghi Congratulations on 3rd! 🎉 Thanks for sharing your work and approach; very insightful.",
    "1781868": "very good one",
    "1780979": "Thank you for the mention :)",
    "1780895": "Congratulations on winning the gold medal 🎉💯\nAlso, thanks for sharing the training code with us.\n\nI' ll learn about your model. \nI look forward to seeing you again at the finance competition 😃",
    "1780840": "@sugghi thanks for this post! I learned some valuable things reading through the feature engineering section :)",
    "1781655": "Congratulations @sugghi...very well done! Thanks for sharing the notebooks. Hope to learn some feature engineering aspects. Wish you the best for other competitions.",
    "1781209": "Yay for Feature Engineering and lgbm ! Also many thanks for sharing the whole code :)",
    "1800466": "",
    "1785952": "",
    "1793885": "thanks for sharing!",
    "2193716": "thanks a lot for sharing your code,"
  },
  "complete": true,
  "source": "existing_discussion",
  "competition_id": 30894,
  "competition_slug": "g-research-crypto-forecasting",
  "team_id": 7653563,
  "solution_url": "/competitions/g-research-crypto-forecasting/writeups/gaba-3rd-place-solution"
}