{
  "id": 311949,
  "title": "All you need is folds",
  "url": "/competitions/ultra-mnist/discussion/311949",
  "author_name": "",
  "post_date": "2022-03-09T16:35:23.814764Z",
  "votes": 4,
  "comment_count": 3,
  "views": 0,
  "content": "<pre><code>import pandas as pd\nfrom sklearn import model_selection\n\ndef create_folds(df, n_folds=5):\n    df = df.sample(frac=1).reset_index(drop=True)\n    y = df['digit_sum'].values\n    kf = model_selection.StratifiedKFold(\n        n_splits=n_folds, \n        shuffle=True ,\n        random_state=42\n    )\n    for f, (t_, v_) in enumerate(kf.split(X=df, y=y)):\n        df.loc[v_, 'fold'] = f\n    df.fold = df.fold.astype(int)\n    print(df.fold.value_counts())\n    df.to_csv(\"train_folds.csv\", index=False)\n\ncreate_folds(train, n_folds=10)\n</code></pre>",
  "messages": [
    {
      "id": "1717079",
      "postDate": "03/09/2022 16:35:23",
      "content": "<pre><code>import pandas as pd\nfrom sklearn import model_selection\n\ndef create_folds(df, n_folds=5):\n    df = df.sample(frac=1).reset_index(drop=True)\n    y = df['digit_sum'].values\n    kf = model_selection.StratifiedKFold(\n        n_splits=n_folds, \n        shuffle=True ,\n        random_state=42\n    )\n    for f, (t_, v_) in enumerate(kf.split(X=df, y=y)):\n        df.loc[v_, 'fold'] = f\n    df.fold = df.fold.astype(int)\n    print(df.fold.value_counts())\n    df.to_csv(\"train_folds.csv\", index=False)\n\ncreate_folds(train, n_folds=10)\n</code></pre>",
      "rawMarkdown": "```\nimport pandas as pd\nfrom sklearn import model_selection\n\ndef create_folds(df, n_folds=5):\n    df = df.sample(frac=1).reset_index(drop=True)\n    y = df['digit_sum'].values\n    kf = model_selection.StratifiedKFold(\n        n_splits=n_folds, \n        shuffle=True ,\n        random_state=42\n    )\n    for f, (t_, v_) in enumerate(kf.split(X=df, y=y)):\n        df.loc[v_, 'fold'] = f\n    df.fold = df.fold.astype(int)\n    print(df.fold.value_counts())\n    df.to_csv(\"train_folds.csv\", index=False)\n\ncreate_folds(train, n_folds=10)\n```",
      "votes": null
    },
    {
      "id": "1717333",
      "postDate": "03/09/2022 20:10:04",
      "content": "<p>What does this mean? please</p>",
      "rawMarkdown": "What does this mean? please",
      "votes": null
    },
    {
      "id": "1717499",
      "postDate": "03/10/2022 01:37:23",
      "content": "<p>nothing,the exact code is not applicable here.He just posted it for some upvotes ig</p>",
      "rawMarkdown": "nothing,the exact code is not applicable here.He just posted it for some upvotes ig",
      "votes": null
    },
    {
      "id": "1717531",
      "postDate": "03/10/2022 02:41:07",
      "content": "<p>Might be wrong but i strongly believe in experiment, why dont you try out? If it is work for you then take it otherwise leave it or ig🤗, nature of the problem is little bit different than usual(classification), Can you correct me how to create leak free folds for this kind of problems? Happy to learn from you🤗 am here to learn not for the upvotes, thanks for your comments👍</p>",
      "rawMarkdown": "Might be wrong but i strongly believe in experiment, why dont you try out? If it is work for you then take it otherwise leave it or ig🤗, nature of the problem is little bit different than usual(classification), Can you correct me how to create leak free folds for this kind of problems? Happy to learn from you🤗 am here to learn not for the upvotes, thanks for your comments👍",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1717333,
      "author_name": "muhammedtausif",
      "author_url": "",
      "post_date": "03/09/2022 20:10:04",
      "content": "<p>What does this mean? please</p>",
      "votes": null,
      "replies": [
        {
          "id": 1717499,
          "author_name": "yaswanthgali",
          "author_url": "",
          "post_date": "03/10/2022 01:37:23",
          "content": "<p>nothing,the exact code is not applicable here.He just posted it for some upvotes ig</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1717531,
          "author_name": "santhoshkumarv",
          "author_url": "",
          "post_date": "03/10/2022 02:41:07",
          "content": "<p>Might be wrong but i strongly believe in experiment, why dont you try out? If it is work for you then take it otherwise leave it or ig🤗, nature of the problem is little bit different than usual(classification), Can you correct me how to create leak free folds for this kind of problems? Happy to learn from you🤗 am here to learn not for the upvotes, thanks for your comments👍</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1717079": "```\nimport pandas as pd\nfrom sklearn import model_selection\n\ndef create_folds(df, n_folds=5):\n    df = df.sample(frac=1).reset_index(drop=True)\n    y = df['digit_sum'].values\n    kf = model_selection.StratifiedKFold(\n        n_splits=n_folds, \n        shuffle=True ,\n        random_state=42\n    )\n    for f, (t_, v_) in enumerate(kf.split(X=df, y=y)):\n        df.loc[v_, 'fold'] = f\n    df.fold = df.fold.astype(int)\n    print(df.fold.value_counts())\n    df.to_csv(\"train_folds.csv\", index=False)\n\ncreate_folds(train, n_folds=10)\n```",
    "1717333": "What does this mean? please",
    "1717499": "nothing,the exact code is not applicable here.He just posted it for some upvotes ig",
    "1717531": "Might be wrong but i strongly believe in experiment, why dont you try out? If it is work for you then take it otherwise leave it or ig🤗, nature of the problem is little bit different than usual(classification), Can you correct me how to create leak free folds for this kind of problems? Happy to learn from you🤗 am here to learn not for the upvotes, thanks for your comments👍"
  },
  "source": "meta"
}