{
  "id": 299498,
  "title": "Making Sense of a Code Snippet Found in Recreating the Target",
  "url": "/competitions/g-research-crypto-forecasting/discussion/299498",
  "author_name": "samuel adeshina",
  "post_date": "2022-01-08T10:57:45.426000",
  "votes": 0,
  "comment_count": 0,
  "views": 0,
  "content": "<p>I found a code snippet in this notebook: <br>\n<a href=\"https://www.kaggle.com/swaralipibose/replacing-nan-targets-with-recreated-targets\" target=\"_blank\">https://www.kaggle.com/swaralipibose/replacing-nan-targets-with-recreated-targets</a></p>\n<p>The notebook is about how to generate the <strong>Target</strong> so as to take care of the nan values in the ones provided by the host of this competition.</p>\n<p>The code snippet is given below:</p>\n<p>`from tqdm import tqdm<br>\ndef compute(df):</p>\n<pre><code>R=list()\nc=list(df['Close'])\nfor i in range(df.shape[0]):\n    future=c[min([i+16,df.shape[0]-1])]\n    past=c[min([i+1,df.shape[0]-1])]\n    R.append(future/past)\nR=np.array(R)\n\ndf['pred']=R-1\nreturn df\n</code></pre>\n<p>crops=list()<br>\nfor a in tqdm(list(range(14))):</p>\n<pre><code>crops.append(compute(df[df['Asset_ID']==a]))`\n</code></pre>\n<p>(1) I don't seem to understand how we came about the <strong>future</strong> and <strong>past</strong> in the code.<br>\n(2) how we knew we should find the ratio of the <strong>future</strong> and <strong>past</strong><br>\n(3) how we made the choice of <strong>16</strong> in [i+16, df.shape[0]-1], knowing we have 14 cryptocurrencies. <br>\n(4) Why we used [i+16,df.shape[0]-1] and [i+1,df.shape[0]-1], and the reason for the <strong>minus 1</strong> here</p>\n<p>Thanks</p>",
  "messages": [
    {
      "id": 1642428,
      "postDate": "2022-01-08T10:57:45.427Z",
      "content": "<p>I found a code snippet in this notebook: <br>\n<a href=\"https://www.kaggle.com/swaralipibose/replacing-nan-targets-with-recreated-targets\" target=\"_blank\">https://www.kaggle.com/swaralipibose/replacing-nan-targets-with-recreated-targets</a></p>\n<p>The notebook is about how to generate the <strong>Target</strong> so as to take care of the nan values in the ones provided by the host of this competition.</p>\n<p>The code snippet is given below:</p>\n<p>`from tqdm import tqdm<br>\ndef compute(df):</p>\n<pre><code>R=list()\nc=list(df['Close'])\nfor i in range(df.shape[0]):\n    future=c[min([i+16,df.shape[0]-1])]\n    past=c[min([i+1,df.shape[0]-1])]\n    R.append(future/past)\nR=np.array(R)\n\ndf['pred']=R-1\nreturn df\n</code></pre>\n<p>crops=list()<br>\nfor a in tqdm(list(range(14))):</p>\n<pre><code>crops.append(compute(df[df['Asset_ID']==a]))`\n</code></pre>\n<p>(1) I don't seem to understand how we came about the <strong>future</strong> and <strong>past</strong> in the code.<br>\n(2) how we knew we should find the ratio of the <strong>future</strong> and <strong>past</strong><br>\n(3) how we made the choice of <strong>16</strong> in [i+16, df.shape[0]-1], knowing we have 14 cryptocurrencies. <br>\n(4) Why we used [i+16,df.shape[0]-1] and [i+1,df.shape[0]-1], and the reason for the <strong>minus 1</strong> here</p>\n<p>Thanks</p>",
      "rawMarkdown": "I found a code snippet in this notebook: \nhttps://www.kaggle.com/swaralipibose/replacing-nan-targets-with-recreated-targets\n\nThe notebook is about how to generate the **Target** so as to take care of the nan values in the ones provided by the host of this competition.\n\nThe code snippet is given below:\n\n`from tqdm import tqdm\ndef compute(df):\n    \n    R=list()\n    c=list(df['Close'])\n    for i in range(df.shape[0]):\n        future=c[min([i+16,df.shape[0]-1])]\n        past=c[min([i+1,df.shape[0]-1])]\n        R.append(future/past)\n    R=np.array(R)\n\n    df['pred']=R-1\n    return df\ncrops=list()\nfor a in tqdm(list(range(14))):\n    \n    crops.append(compute(df[df['Asset_ID']==a]))`\n\n(1) I don't seem to understand how we came about the **future** and **past** in the code.\n(2) how we knew we should find the ratio of the **future** and **past**\n(3) how we made the choice of **16** in [i+16, df.shape[0]-1], knowing we have 14 cryptocurrencies. \n(4) Why we used [i+16,df.shape[0]-1] and [i+1,df.shape[0]-1], and the reason for the **minus 1** here\n\nThanks"
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "1642428": "I found a code snippet in this notebook: \nhttps://www.kaggle.com/swaralipibose/replacing-nan-targets-with-recreated-targets\n\nThe notebook is about how to generate the **Target** so as to take care of the nan values in the ones provided by the host of this competition.\n\nThe code snippet is given below:\n\n`from tqdm import tqdm\ndef compute(df):\n    \n    R=list()\n    c=list(df['Close'])\n    for i in range(df.shape[0]):\n        future=c[min([i+16,df.shape[0]-1])]\n        past=c[min([i+1,df.shape[0]-1])]\n        R.append(future/past)\n    R=np.array(R)\n\n    df['pred']=R-1\n    return df\ncrops=list()\nfor a in tqdm(list(range(14))):\n    \n    crops.append(compute(df[df['Asset_ID']==a]))`\n\n(1) I don't seem to understand how we came about the **future** and **past** in the code.\n(2) how we knew we should find the ratio of the **future** and **past**\n(3) how we made the choice of **16** in [i+16, df.shape[0]-1], knowing we have 14 cryptocurrencies. \n(4) Why we used [i+16,df.shape[0]-1] and [i+1,df.shape[0]-1], and the reason for the **minus 1** here\n\nThanks"
  }
}