{
  "id": 67720,
  "title": "Target Encoding in R",
  "url": "/competitions/ga-customer-revenue-prediction/discussion/67720",
  "author_name": "",
  "post_date": "2018-10-04T17:36:25.810576200Z",
  "votes": null,
  "comment_count": 6,
  "views": 0,
  "content": "<p>Since some of the categorical variables have such high carnality, I would like to try target encoding them. But, I would like to generate them out of sample like discussed here <a href=\"https://www.kaggle.com/c/ga-customer-revenue-prediction/discussion/66260\">https://www.kaggle.com/c/ga-customer-revenue-prediction/discussion/66260</a>.  Does anybody know of a package in R that does the target encoding out of sample? I tried making my own function, but did not have much success.</p>\n\n<p>Thanks in advance!</p>",
  "messages": [
    {
      "id": "398859",
      "postDate": "10/04/2018 17:36:25",
      "content": "<p>Since some of the categorical variables have such high carnality, I would like to try target encoding them. But, I would like to generate them out of sample like discussed here <a href=\"https://www.kaggle.com/c/ga-customer-revenue-prediction/discussion/66260\">https://www.kaggle.com/c/ga-customer-revenue-prediction/discussion/66260</a>.  Does anybody know of a package in R that does the target encoding out of sample? I tried making my own function, but did not have much success.</p>\n\n<p>Thanks in advance!</p>",
      "rawMarkdown": "Since some of the categorical variables have such high carnality, I would like to try target encoding them. But, I would like to generate them out of sample like discussed here [https://www.kaggle.com/c/ga-customer-revenue-prediction/discussion/66260][1].  Does anybody know of a package in R that does the target encoding out of sample? I tried making my own function, but did not have much success.\n\nThanks in advance!\n\n\n  [1]: https://www.kaggle.com/c/ga-customer-revenue-prediction/discussion/66260",
      "votes": null
    },
    {
      "id": "398980",
      "postDate": "10/04/2018 22:40:01",
      "content": "<p>I don't know if there is a package to do this in R. However, you can use reticulate and import some python function to apply  target encoding .</p>",
      "rawMarkdown": "I don't know if there is a package to do this in R. However, you can use reticulate and import some python function to apply  target encoding .",
      "votes": null
    },
    {
      "id": "399006",
      "postDate": "10/05/2018 01:33:55",
      "content": "<p>data.table solution:</p>\n\n<pre><code>tmp &lt;- train[,mean(totals.transactionRevenue), by=CATEGORICAL_VAR]\ntrain &lt;- merge(train, tmp, by=CATEGORICAL_VAR, all.x=TRUE)\ntest &lt;- merge(test, tmp, by=CATEGORICAL_VAR, all.x=TRUE)\n</code></pre>",
      "rawMarkdown": "data.table solution:\n\n    tmp &lt;- train[,mean(totals.transactionRevenue), by=CATEGORICAL_VAR]\n    train &lt;- merge(train, tmp, by=CATEGORICAL_VAR, all.x=TRUE)\n    test &lt;- merge(test, tmp, by=CATEGORICAL_VAR, all.x=TRUE)",
      "votes": null
    },
    {
      "id": "399574",
      "postDate": "10/06/2018 05:53:37",
      "content": "<p>Thanks for the advice!</p>",
      "rawMarkdown": "Thanks for the advice!",
      "votes": null
    },
    {
      "id": "399575",
      "postDate": "10/06/2018 05:55:05",
      "content": "<p>Thank you! I'd like to implement the target encoding out of sample. Like a K-Fold sort of thing. I'll see if I can take this code and modify it. </p>",
      "rawMarkdown": "Thank you! I'd like to implement the target encoding out of sample. Like a K-Fold sort of thing. I'll see if I can take this code and modify it.",
      "votes": null
    },
    {
      "id": "399688",
      "postDate": "10/06/2018 13:35:22",
      "content": "<p>Maybe this can be helpful: <a href=\"http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-munging/target-encoding.html\">http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-munging/target-encoding.html</a></p>",
      "rawMarkdown": "Maybe this can be helpful: http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-munging/target-encoding.html",
      "votes": null
    },
    {
      "id": "399719",
      "postDate": "10/06/2018 15:17:51",
      "content": "<p>There was a public kernel by <a href=\"/raddar\">@raddar</a> with target encoding <strong>with KFold regularisation</strong>:</p>\n\n<p><a href=\"https://www.kaggle.com/raddar/raddar-extratrees\">https://www.kaggle.com/raddar/raddar-extratrees</a></p>\n\n<p>This was one of top results in the Mersedes Benz comp. I actually do not know R, but I was following the duscussion, which led to this kernel</p>",
      "rawMarkdown": "There was a public kernel by @raddar with target encoding **with KFold regularisation**:\n\nhttps://www.kaggle.com/raddar/raddar-extratrees\n\n This was one of top results in the Mersedes Benz comp. I actually do not know R, but I was following the duscussion, which led to this kernel",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 398980,
      "author_name": "paulofelipe",
      "author_url": "",
      "post_date": "10/04/2018 22:40:01",
      "content": "<p>I don't know if there is a package to do this in R. However, you can use reticulate and import some python function to apply  target encoding .</p>",
      "votes": null,
      "replies": [
        {
          "id": 399574,
          "author_name": "obrienmitch94",
          "author_url": "",
          "post_date": "10/06/2018 05:53:37",
          "content": "<p>Thanks for the advice!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 399006,
      "author_name": "returnofsputnik",
      "author_url": "",
      "post_date": "10/05/2018 01:33:55",
      "content": "<p>data.table solution:</p>\n\n<pre><code>tmp &lt;- train[,mean(totals.transactionRevenue), by=CATEGORICAL_VAR]\ntrain &lt;- merge(train, tmp, by=CATEGORICAL_VAR, all.x=TRUE)\ntest &lt;- merge(test, tmp, by=CATEGORICAL_VAR, all.x=TRUE)\n</code></pre>",
      "votes": null,
      "replies": [
        {
          "id": 399575,
          "author_name": "obrienmitch94",
          "author_url": "",
          "post_date": "10/06/2018 05:55:05",
          "content": "<p>Thank you! I'd like to implement the target encoding out of sample. Like a K-Fold sort of thing. I'll see if I can take this code and modify it. </p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 399688,
      "author_name": "paulofelipe",
      "author_url": "",
      "post_date": "10/06/2018 13:35:22",
      "content": "<p>Maybe this can be helpful: <a href=\"http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-munging/target-encoding.html\">http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-munging/target-encoding.html</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 399719,
      "author_name": "mlisovyi",
      "author_url": "",
      "post_date": "10/06/2018 15:17:51",
      "content": "<p>There was a public kernel by <a href=\"/raddar\">@raddar</a> with target encoding <strong>with KFold regularisation</strong>:</p>\n\n<p><a href=\"https://www.kaggle.com/raddar/raddar-extratrees\">https://www.kaggle.com/raddar/raddar-extratrees</a></p>\n\n<p>This was one of top results in the Mersedes Benz comp. I actually do not know R, but I was following the duscussion, which led to this kernel</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "398859": "Since some of the categorical variables have such high carnality, I would like to try target encoding them. But, I would like to generate them out of sample like discussed here [https://www.kaggle.com/c/ga-customer-revenue-prediction/discussion/66260][1].  Does anybody know of a package in R that does the target encoding out of sample? I tried making my own function, but did not have much success.\n\nThanks in advance!\n\n\n  [1]: https://www.kaggle.com/c/ga-customer-revenue-prediction/discussion/66260",
    "398980": "I don't know if there is a package to do this in R. However, you can use reticulate and import some python function to apply  target encoding .",
    "399006": "data.table solution:\n\n    tmp &lt;- train[,mean(totals.transactionRevenue), by=CATEGORICAL_VAR]\n    train &lt;- merge(train, tmp, by=CATEGORICAL_VAR, all.x=TRUE)\n    test &lt;- merge(test, tmp, by=CATEGORICAL_VAR, all.x=TRUE)",
    "399574": "Thanks for the advice!",
    "399575": "Thank you! I'd like to implement the target encoding out of sample. Like a K-Fold sort of thing. I'll see if I can take this code and modify it.",
    "399688": "Maybe this can be helpful: http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-munging/target-encoding.html",
    "399719": "There was a public kernel by @raddar with target encoding **with KFold regularisation**:\n\nhttps://www.kaggle.com/raddar/raddar-extratrees\n\n This was one of top results in the Mersedes Benz comp. I actually do not know R, but I was following the duscussion, which led to this kernel"
  },
  "source": "meta"
}