{
  "id": 11433,
  "title": "High number of levels in some features",
  "url": "/competitions/avazu-ctr-prediction/discussion/11433",
  "author_name": "",
  "post_date": "2015-01-06T00:37:58.577Z",
  "votes": null,
  "comment_count": 26,
  "views": 9339,
  "content": "<p>Hi,</p>\n<p><br>Beginner getting some experience. I want to try logistic regression and SVM, but there are some features that have lots of levels, the option I know is to use dummy features, is there any other option?, because I end up with a high dimensionality dataset.</p>\n<p>Any suggestions?</p>\n<p>Thanks in advance</p>",
  "messages": [
    {
      "id": "62321",
      "postDate": "01/06/2015 00:37:58",
      "content": "<p>Hi,</p>\n<p><br>Beginner getting some experience. I want to try logistic regression and SVM, but there are some features that have lots of levels, the option I know is to use dummy features, is there any other option?, because I end up with a high dimensionality dataset.</p>\n<p>Any suggestions?</p>\n<p>Thanks in advance</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62322",
      "postDate": "01/06/2015 01:56:43",
      "content": "<p>A few of thoughts you might consider:</p>\n<p>1) Start without those features</p>\n<p>2) Convert a column of features into a single, continuous feature by replacing each individual feature with the overall average of that feature.</p>\n<p>3) Figure out which features have the most leverage, and just use those.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62340",
      "postDate": "01/06/2015 12:13:58",
      "content": "<p>Thank you very much, inversion.</p>\n<p>In the case of the point 2. Did you mean &quot;columns of features&quot; right?, and could you give an example of how do I have to get those averages?. Thanks again.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62355",
      "postDate": "01/06/2015 15:41:33",
      "content": "<p>Yup. Something like this:</p>\n<p><img src=\"http://i.imgur.com/yF6RS61.png\" alt width=\"140\" height=\"183\"></p>\n<p>You can do it using &quot;brute force&quot; by writing a loop that counts the number of clicks for each feature, divide by the occurrence of each feature, and then replace each feature with that average.</p>\n<p>There are, of course, more elegant ways to do this, which depend on whether you are using Python, R, etc.</p>\n<p>A google search should be able to get you what you need for your specific setup.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62356",
      "postDate": "01/06/2015 15:43:37",
      "content": "<p>@inversion: i really like the idea (and I've seen it used in other contests), but don't you run a risk of overfitting? after all, you are building your features using values from the target you are trying to predict...</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62358",
      "postDate": "01/06/2015 16:02:02",
      "content": "<p>[quote=Konrad Banachewicz;62356]</p>\n<p>@inversion: i really like the idea (and I've seen it used in other contests), but don't you run a risk of overfitting? after all, you are building your features using values from the target you are trying to predict...</p>\n<p>[/quote]</p>\n<p>Thanks for making that point, which is definitely a consideration.</p>\n<p>I was approaching the question not from the perspective of &quot;what is the best method to try&quot; but from the perspective of &quot;how can I easily get started&quot;.</p>\n<p>In other words, for a beginner (well, perhaps even in general), it's good to see if you can get your model to work with a few columns and features. How well did it do? How long did it take? If I can't get my model to work in a simplified case, chances are I won't get it to work in the more complicated case.</p>\n<p>For a beginner (and perhaps even generally), it's a simple thing to try and see what happens. But, to your point, there is risk that should be assessed.</p>\n<p>(My opinion:&nbsp;I'm not sure over-fitting is going to be much of a problem&nbsp;for this contest.&nbsp;I've tried very hard to over-fit, without much success. I think there is just too much probabilistic noise in the data. But I could be wrong.)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62359",
      "postDate": "01/06/2015 16:14:37",
      "content": "<p>[quote=Konrad Banachewicz;62356]</p>\n<p>@inversion: i really like the idea (and I've seen it used in other contests), but don't you run a risk of overfitting? after all, you are building your features using values from the target you are trying to predict...</p>\n<p>[/quote]</p>\n<p>It might cause overfitting, especially if&nbsp;decision tree based learners would be used. I think it would be a better idea to do some kind of smoothing, ie. instead of sum(click)/N, you could use something like (sum(click)+alpha)/(N+2*alpha), where alpha&gt;0. (I think it's called Laplace smoothing, which correspond to certain kind of Bayesian prior&amp;likelihood). Then, at least infrequent features would be closer together which would prevent at least some forms of overfitting.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62362",
      "postDate": "01/06/2015 16:32:23",
      "content": "<p>@inversion: not sure if I agree about this being difficult to overfit: 1. i am consistently seeing a discrepancy between my validation vs lb score (in the wrong direction :-) 2. the issue might be related to the fact that the test day (= Halloween) seems to be somewhat different qualitatively different from the training set (there is a discussion about that in the forum).</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62364",
      "postDate": "01/06/2015 16:34:31",
      "content": "<p>[quote=Herra Huu;62359]</p>\n<p>&nbsp;I think it would be a better idea to do some kind of smoothing, ie. instead of sum(click)/N, you could use something like (sum(click)+alpha)/(N+2*alpha), where alpha&gt;0. (I think it's called Laplace smoothing, which correspond to certain kind of Bayesian prior&amp;likelihood). Then, at least infrequent features would be closer together which would prevent at least some forms of overfitting.</p>\n<p>[/quote]</p>\n<p>That is certainly a good approach, I am wondering if that's enough (or, in light of the Helloween thing, is that even treating the core issue). Due to my not-that-modern hardware, I have some optimizing to do before I can attempt it :-)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62366",
      "postDate": "01/06/2015 16:59:08",
      "content": "<p>[quote=Konrad Banachewicz;62364]</p>\n<p>That is certainly a good approach, I am wondering if that's enough (or, in light of the Helloween thing, is that even treating the core issue).</p>\n<p>[/quote]</p>\n<p>Yeah, it's not necessary enough (depending on what kind of model/distributions of values etc). For example even with smoothing, all features with count==1 would be&nbsp;presented by some values x_0 (click==0) and x_1 (click==1). Then decision tree based algorithms could separate those rows from everything else with just a couple of splits =&gt; possibly huge overfitting problem (if there is many such features). I think another good idea would be at least remove rare features (say count&lt;5). But as usual, it depends.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62367",
      "postDate": "01/06/2015 16:59:21",
      "content": "<p>[quote=Konrad Banachewicz;62362]</p>\n<p>@inversion: not sure if I agree about this being difficult to overfit: 1. i am consistently seeing a discrepancy between my validation vs lb score (in the wrong direction :-) 2. the issue might be related to the fact that the test day (= Halloween) seems to be somewhat different qualitatively different from the training set (there is a discussion about that in the forum).</p>\n<p>[/quote]</p>\n<p>As I've <a href=\"https://www.kaggle.com/c/avazu-ctr-prediction/forums/t/11379/rare-feature-removal-effective/62103#post62103\">posted earlier</a>, my validation scores have&nbsp;tracked nicely with LB score.</p>\n<p>It's like the old joke:</p>\n<ul>\n<li><span style=\"line-height: 1.4\">My validation&nbsp;score doesn't track with the leader board score . . . I have no idea&nbsp;why.</span></li>\n<li><span style=\"line-height: 1.4\">My validation score is tracking&nbsp;with the leader board score . . . I have no idea&nbsp;why.</span></li>\n</ul>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62368",
      "postDate": "01/06/2015 17:02:17",
      "content": "<p>P.S. Here's the reference for those who have not seen it.</p>\n<p><img src=\"https://pbs.twimg.com/media/A6PSWTFCUAI7N-5.jpg\" alt width=\"550\" height=\"840\"></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62380",
      "postDate": "01/06/2015 23:02:02",
      "content": "<p>[quote=Herra Huu;62366]</p>\n<p>Yeah, it's not necessary enough (depending on what kind of model/distributions of values etc). For example even with smoothing, all features with count==1 would be&nbsp;presented by some values x_0 (click==0) and x_1 (click==1). Then decision tree based algorithms could separate those rows from everything else with just a couple of splits =&gt; possibly huge overfitting problem (if there is many such features). I think another good idea would be at least remove rare features (say count&lt;5). But as usual, it depends.</p>\n<p>[/quote]</p>\n<p>For smaller data sets, I have fit a random effects model to each categorical variable. Making the category a random effect shrinks the estimate towards the mean. I wonder for these other purposes, perhaps averaging across a few bootstrap samples could help reduce overfiting.&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62397",
      "postDate": "01/07/2015 12:14:35",
      "content": "<p>[quote=Ofd;62321]</p>\n<p>[/quote]</p>\n<p>attached&nbsp;R code would give you a head start . &nbsp;:-)</p>\n<p>cheers</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62399",
      "postDate": "01/07/2015 14:56:03",
      "content": "<p>Thanks to all that who gave his approach in this post.&nbsp;it's a great learning journey with this community :-)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62406",
      "postDate": "01/07/2015 16:07:17",
      "content": "<p>It is possible to get a reasonable score via the CTR histogram approach but my first efforts couldn't quite break the 0.40 level, from a 5m sample. If you are using R you might want to consider:</p>\n<p>- the combine.levels function from Hmisc to easily drop infrequent categories</p>\n<p>- the ave function to easily cacluate the CTR for each level you retain&nbsp;(though without any smoothing)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62413",
      "postDate": "01/07/2015 18:09:28",
      "content": "<p>[quote=lewis ml;62406]</p>\n<p>It is possible to get a reasonable score via the CTR histogram approach but my first efforts couldn't quite break the 0.40 level, from a 5m sample. If you are using R you might want to consider:</p>\n<p>- the combine.levels function from Hmisc to easily drop infrequent categories</p>\n<p>- the ave function to easily cacluate the CTR for each level you retain&nbsp;(though without any smoothing)</p>\n<p>[/quote]</p>\n\n<p>@Lewis ML, would you please elaborate on the CTR histogram approach a bit more? &nbsp;I saw it mentioned from the previous competition, but couldn't actually get the gist of it... thank you in advance!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62415",
      "postDate": "01/07/2015 18:35:03",
      "content": "<p>Sure, though I'm no expert on it. As inversion described above, you:</p>\n<p>- remove infrequent levels from each variable</p>\n<p>- calculate the ctr for each level of each variable</p>\n<p>- use those new numeric features as the inputs to a gradient boosted tree</p>\n<p>As with other methods you can add features by combining levels across variables.</p>\n<p>I'm not sure if the small sample was the limiting factor on my effort. I tried both gbm and xgb via R.</p>\n<p>fchollet and the xgb authors deserve the credit for the idea.&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62485",
      "postDate": "01/09/2015 08:21:52",
      "content": "<p>Hi all,</p>\n<p>My last unsuccessful attempt with CTR is as follows:</p>\n<p>For each day calculate CTR per variable and per hour excepted for the last day (10th day). At the end, I had a bunch of features from all 9 days (around 150) which I merged to the 10th day for training using hour as key. </p>\n<p>Good Luck,</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62504",
      "postDate": "01/09/2015 15:12:56",
      "content": "<p>[quote=lewis ml;62415]</p>\n<p>Sure, though I'm no expert on it. As inversion described above, you:</p>\n<p>- remove infrequent levels from each variable</p>\n<p>- calculate the ctr for each level of each variable</p>\n<p>- use those new numeric features as the inputs to a gradient boosted tree</p>\n<p>As with other methods you can add features by combining levels across variables.</p>\n<p>I'm not sure if the small sample was the limiting factor on my effort. I tried both gbm and xgb via R.</p>\n<p>fchollet and the xgb authors deserve the credit for the idea.</p>\n<p>[/quote]</p>\n<p>Thank you for the explanation, Lewis ML. What you explained, Inversion's post, and the previous comments now all connects. I tried to replace each variable by the mean CTR at the beginning of the competition, but didn't see much result. Maybe because I didn't remove rare features, or didn't do Laplace smoothing as Herra Huu suggested. &nbsp;I will give it another try and let you guys know if I see any improvements.&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62505",
      "postDate": "01/09/2015 15:41:16",
      "content": "<p>@DerekZH -</p>\n<p>Also note, this method doesn't account for the interactions between features. So, if this data set has strong interactions, you wouldn't expect it to do as well as methods that account for the interactions.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62580",
      "postDate": "01/10/2015 18:59:36",
      "content": "<p>[quote=inversion;62505]</p>\n<p>@DerekZH -</p>\n<p>Also note, this method doesn't account for the interactions between features. So, if this data set has strong interactions, you wouldn't expect it to do as well as methods that account for the interactions.</p>\n<p>[/quote]</p>\n<p>I appreciate this insight, Inversion. &nbsp;I will try to give the CTR histogram approach another try, just to learn the approach, and make it a candidate for later ensemble. &nbsp;And I will give more thoughts to accounting for feature interactions. &nbsp;</p>\n<p>Thanks again :)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62853",
      "postDate": "01/18/2015 06:28:50",
      "content": "<p>In this case, How would you prepare the test set for prediction as It does not contain 'click'</p>\n<p>[quote=inversion;62355]</p>\n<p>Yup. Something like this:</p>\n<p><img src=\"http://i.imgur.com/yF6RS61.png\" alt width=\"140\" height=\"183\"></p>\n<p>You can do it using &quot;brute force&quot; by writing a loop that counts the number of clicks for each feature, divide by the occurrence of each feature, and then replace each feature with that average.</p>\n<p>There are, of course, more elegant ways to do this, which depend on whether you are using Python, R, etc.</p>\n<p>A google search should be able to get you what you need for your specific setup.</p>\n<p>[/quote]</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62854",
      "postDate": "01/18/2015 08:05:16",
      "content": "<p>@inversion &nbsp;@lewis ml</p>\n<p>Thank lewis and inversion for bringing us the idea and explanation. &nbsp;</p>\n<p>There is one thing I'm still not clear is how do we deal with the null value in dataset?&nbsp;I think it is obviously not a good idea&nbsp;to consider those null values&nbsp;as unseen features in test dataset and allocate a smoothing value to them (eg, 0.25).</p>\n<p>So should we just conclude these null values as a new category and calculate the average CTR for this category, or do we&nbsp;just keep them as null values in dataset?</p>\n<p>Thanks :)</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62855",
      "postDate": "01/18/2015 08:51:51",
      "content": "<p>Herimanitra: you have to build the test set by looking up the relevant ctr from the train set. So with inversion's example, any test case with A gets a 0.75 for that ctr feature.</p>\n<p>Ivan: you raise a good point but I'm not sure there's an &nbsp;obvious 'right' way to deal with the issue. Might be worth trying different treatments.</p>\n<p>inversion: I feel like I'm missing something on your point about interactions. You can add interactions by creating a new categorical feature from two existing features, then calculating the ctr for it. But are saying you wouldn't expect that to be effective?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62860",
      "postDate": "01/18/2015 15:04:38",
      "content": "<p>[quote=lewis ml;62855]</p>\n<p>inversion: I feel like I'm missing something on your point about interactions. You can add interactions by creating a new categorical feature from two existing features, then calculating the ctr for it. But are saying you wouldn't expect that to be effective?</p>\n<p>[/quote]</p>\n<p>You're absolutely right . . . what I was trying to convey was that if you just reduced the feature set&nbsp;<em>as is</em> to average&nbsp;CTRs, you shouldn't necessarily expect a decent score. But there's no reason you couldn't build interactions as you suggest.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62861",
      "postDate": "01/18/2015 15:07:18",
      "content": "<p>[quote=Ivan Liu;62854]</p>\n<p>@inversion &nbsp;@lewis ml</p>\n<p>So should we just conclude these null values as a new category and calculate the average CTR for this category, or do we&nbsp;just keep them as null values in dataset?</p>\n<p>Thanks :)</p>\n<p>[/quote]</p>\n<p>I've tried both ways . . . it's far less a hassle to change nulls to a new categorical feature.</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 62322,
      "author_name": "inversion",
      "author_url": "",
      "post_date": "01/06/2015 01:56:43",
      "content": "<p>A few of thoughts you might consider:</p>\n<p>1) Start without those features</p>\n<p>2) Convert a column of features into a single, continuous feature by replacing each individual feature with the overall average of that feature.</p>\n<p>3) Figure out which features have the most leverage, and just use those.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62340,
      "author_name": "ofdomejean",
      "author_url": "",
      "post_date": "01/06/2015 12:13:58",
      "content": "<p>Thank you very much, inversion.</p>\n<p>In the case of the point 2. Did you mean &quot;columns of features&quot; right?, and could you give an example of how do I have to get those averages?. Thanks again.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62355,
      "author_name": "inversion",
      "author_url": "",
      "post_date": "01/06/2015 15:41:33",
      "content": "<p>Yup. Something like this:</p>\n<p><img src=\"http://i.imgur.com/yF6RS61.png\" alt width=\"140\" height=\"183\"></p>\n<p>You can do it using &quot;brute force&quot; by writing a loop that counts the number of clicks for each feature, divide by the occurrence of each feature, and then replace each feature with that average.</p>\n<p>There are, of course, more elegant ways to do this, which depend on whether you are using Python, R, etc.</p>\n<p>A google search should be able to get you what you need for your specific setup.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62356,
      "author_name": "konradb",
      "author_url": "",
      "post_date": "01/06/2015 15:43:37",
      "content": "<p>@inversion: i really like the idea (and I've seen it used in other contests), but don't you run a risk of overfitting? after all, you are building your features using values from the target you are trying to predict...</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62358,
      "author_name": "inversion",
      "author_url": "",
      "post_date": "01/06/2015 16:02:02",
      "content": "<p>[quote=Konrad Banachewicz;62356]</p>\n<p>@inversion: i really like the idea (and I've seen it used in other contests), but don't you run a risk of overfitting? after all, you are building your features using values from the target you are trying to predict...</p>\n<p>[/quote]</p>\n<p>Thanks for making that point, which is definitely a consideration.</p>\n<p>I was approaching the question not from the perspective of &quot;what is the best method to try&quot; but from the perspective of &quot;how can I easily get started&quot;.</p>\n<p>In other words, for a beginner (well, perhaps even in general), it's good to see if you can get your model to work with a few columns and features. How well did it do? How long did it take? If I can't get my model to work in a simplified case, chances are I won't get it to work in the more complicated case.</p>\n<p>For a beginner (and perhaps even generally), it's a simple thing to try and see what happens. But, to your point, there is risk that should be assessed.</p>\n<p>(My opinion:&nbsp;I'm not sure over-fitting is going to be much of a problem&nbsp;for this contest.&nbsp;I've tried very hard to over-fit, without much success. I think there is just too much probabilistic noise in the data. But I could be wrong.)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62359,
      "author_name": "herrahuu",
      "author_url": "",
      "post_date": "01/06/2015 16:14:37",
      "content": "<p>[quote=Konrad Banachewicz;62356]</p>\n<p>@inversion: i really like the idea (and I've seen it used in other contests), but don't you run a risk of overfitting? after all, you are building your features using values from the target you are trying to predict...</p>\n<p>[/quote]</p>\n<p>It might cause overfitting, especially if&nbsp;decision tree based learners would be used. I think it would be a better idea to do some kind of smoothing, ie. instead of sum(click)/N, you could use something like (sum(click)+alpha)/(N+2*alpha), where alpha&gt;0. (I think it's called Laplace smoothing, which correspond to certain kind of Bayesian prior&amp;likelihood). Then, at least infrequent features would be closer together which would prevent at least some forms of overfitting.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62362,
      "author_name": "konradb",
      "author_url": "",
      "post_date": "01/06/2015 16:32:23",
      "content": "<p>@inversion: not sure if I agree about this being difficult to overfit: 1. i am consistently seeing a discrepancy between my validation vs lb score (in the wrong direction :-) 2. the issue might be related to the fact that the test day (= Halloween) seems to be somewhat different qualitatively different from the training set (there is a discussion about that in the forum).</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62364,
      "author_name": "konradb",
      "author_url": "",
      "post_date": "01/06/2015 16:34:31",
      "content": "<p>[quote=Herra Huu;62359]</p>\n<p>&nbsp;I think it would be a better idea to do some kind of smoothing, ie. instead of sum(click)/N, you could use something like (sum(click)+alpha)/(N+2*alpha), where alpha&gt;0. (I think it's called Laplace smoothing, which correspond to certain kind of Bayesian prior&amp;likelihood). Then, at least infrequent features would be closer together which would prevent at least some forms of overfitting.</p>\n<p>[/quote]</p>\n<p>That is certainly a good approach, I am wondering if that's enough (or, in light of the Helloween thing, is that even treating the core issue). Due to my not-that-modern hardware, I have some optimizing to do before I can attempt it :-)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62366,
      "author_name": "herrahuu",
      "author_url": "",
      "post_date": "01/06/2015 16:59:08",
      "content": "<p>[quote=Konrad Banachewicz;62364]</p>\n<p>That is certainly a good approach, I am wondering if that's enough (or, in light of the Helloween thing, is that even treating the core issue).</p>\n<p>[/quote]</p>\n<p>Yeah, it's not necessary enough (depending on what kind of model/distributions of values etc). For example even with smoothing, all features with count==1 would be&nbsp;presented by some values x_0 (click==0) and x_1 (click==1). Then decision tree based algorithms could separate those rows from everything else with just a couple of splits =&gt; possibly huge overfitting problem (if there is many such features). I think another good idea would be at least remove rare features (say count&lt;5). But as usual, it depends.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62367,
      "author_name": "inversion",
      "author_url": "",
      "post_date": "01/06/2015 16:59:21",
      "content": "<p>[quote=Konrad Banachewicz;62362]</p>\n<p>@inversion: not sure if I agree about this being difficult to overfit: 1. i am consistently seeing a discrepancy between my validation vs lb score (in the wrong direction :-) 2. the issue might be related to the fact that the test day (= Halloween) seems to be somewhat different qualitatively different from the training set (there is a discussion about that in the forum).</p>\n<p>[/quote]</p>\n<p>As I've <a href=\"https://www.kaggle.com/c/avazu-ctr-prediction/forums/t/11379/rare-feature-removal-effective/62103#post62103\">posted earlier</a>, my validation scores have&nbsp;tracked nicely with LB score.</p>\n<p>It's like the old joke:</p>\n<ul>\n<li><span style=\"line-height: 1.4\">My validation&nbsp;score doesn't track with the leader board score . . . I have no idea&nbsp;why.</span></li>\n<li><span style=\"line-height: 1.4\">My validation score is tracking&nbsp;with the leader board score . . . I have no idea&nbsp;why.</span></li>\n</ul>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62368,
      "author_name": "inversion",
      "author_url": "",
      "post_date": "01/06/2015 17:02:17",
      "content": "<p>P.S. Here's the reference for those who have not seen it.</p>\n<p><img src=\"https://pbs.twimg.com/media/A6PSWTFCUAI7N-5.jpg\" alt width=\"550\" height=\"840\"></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62380,
      "author_name": "inspector",
      "author_url": "",
      "post_date": "01/06/2015 23:02:02",
      "content": "<p>[quote=Herra Huu;62366]</p>\n<p>Yeah, it's not necessary enough (depending on what kind of model/distributions of values etc). For example even with smoothing, all features with count==1 would be&nbsp;presented by some values x_0 (click==0) and x_1 (click==1). Then decision tree based algorithms could separate those rows from everything else with just a couple of splits =&gt; possibly huge overfitting problem (if there is many such features). I think another good idea would be at least remove rare features (say count&lt;5). But as usual, it depends.</p>\n<p>[/quote]</p>\n<p>For smaller data sets, I have fit a random effects model to each categorical variable. Making the category a random effect shrinks the estimate towards the mean. I wonder for these other purposes, perhaps averaging across a few bootstrap samples could help reduce overfiting.&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62397,
      "author_name": "namesj",
      "author_url": "",
      "post_date": "01/07/2015 12:14:35",
      "content": "<p>[quote=Ofd;62321]</p>\n<p>[/quote]</p>\n<p>attached&nbsp;R code would give you a head start . &nbsp;:-)</p>\n<p>cheers</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62399,
      "author_name": "ofdomejean",
      "author_url": "",
      "post_date": "01/07/2015 14:56:03",
      "content": "<p>Thanks to all that who gave his approach in this post.&nbsp;it's a great learning journey with this community :-)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62406,
      "author_name": "cartographic",
      "author_url": "",
      "post_date": "01/07/2015 16:07:17",
      "content": "<p>It is possible to get a reasonable score via the CTR histogram approach but my first efforts couldn't quite break the 0.40 level, from a 5m sample. If you are using R you might want to consider:</p>\n<p>- the combine.levels function from Hmisc to easily drop infrequent categories</p>\n<p>- the ave function to easily cacluate the CTR for each level you retain&nbsp;(though without any smoothing)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62413,
      "author_name": "derekzh",
      "author_url": "",
      "post_date": "01/07/2015 18:09:28",
      "content": "<p>[quote=lewis ml;62406]</p>\n<p>It is possible to get a reasonable score via the CTR histogram approach but my first efforts couldn't quite break the 0.40 level, from a 5m sample. If you are using R you might want to consider:</p>\n<p>- the combine.levels function from Hmisc to easily drop infrequent categories</p>\n<p>- the ave function to easily cacluate the CTR for each level you retain&nbsp;(though without any smoothing)</p>\n<p>[/quote]</p>\n\n<p>@Lewis ML, would you please elaborate on the CTR histogram approach a bit more? &nbsp;I saw it mentioned from the previous competition, but couldn't actually get the gist of it... thank you in advance!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62415,
      "author_name": "cartographic",
      "author_url": "",
      "post_date": "01/07/2015 18:35:03",
      "content": "<p>Sure, though I'm no expert on it. As inversion described above, you:</p>\n<p>- remove infrequent levels from each variable</p>\n<p>- calculate the ctr for each level of each variable</p>\n<p>- use those new numeric features as the inputs to a gradient boosted tree</p>\n<p>As with other methods you can add features by combining levels across variables.</p>\n<p>I'm not sure if the small sample was the limiting factor on my effort. I tried both gbm and xgb via R.</p>\n<p>fchollet and the xgb authors deserve the credit for the idea.&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62485,
      "author_name": "herimanitra",
      "author_url": "",
      "post_date": "01/09/2015 08:21:52",
      "content": "<p>Hi all,</p>\n<p>My last unsuccessful attempt with CTR is as follows:</p>\n<p>For each day calculate CTR per variable and per hour excepted for the last day (10th day). At the end, I had a bunch of features from all 9 days (around 150) which I merged to the 10th day for training using hour as key. </p>\n<p>Good Luck,</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62504,
      "author_name": "derekzh",
      "author_url": "",
      "post_date": "01/09/2015 15:12:56",
      "content": "<p>[quote=lewis ml;62415]</p>\n<p>Sure, though I'm no expert on it. As inversion described above, you:</p>\n<p>- remove infrequent levels from each variable</p>\n<p>- calculate the ctr for each level of each variable</p>\n<p>- use those new numeric features as the inputs to a gradient boosted tree</p>\n<p>As with other methods you can add features by combining levels across variables.</p>\n<p>I'm not sure if the small sample was the limiting factor on my effort. I tried both gbm and xgb via R.</p>\n<p>fchollet and the xgb authors deserve the credit for the idea.</p>\n<p>[/quote]</p>\n<p>Thank you for the explanation, Lewis ML. What you explained, Inversion's post, and the previous comments now all connects. I tried to replace each variable by the mean CTR at the beginning of the competition, but didn't see much result. Maybe because I didn't remove rare features, or didn't do Laplace smoothing as Herra Huu suggested. &nbsp;I will give it another try and let you guys know if I see any improvements.&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62505,
      "author_name": "inversion",
      "author_url": "",
      "post_date": "01/09/2015 15:41:16",
      "content": "<p>@DerekZH -</p>\n<p>Also note, this method doesn't account for the interactions between features. So, if this data set has strong interactions, you wouldn't expect it to do as well as methods that account for the interactions.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62580,
      "author_name": "derekzh",
      "author_url": "",
      "post_date": "01/10/2015 18:59:36",
      "content": "<p>[quote=inversion;62505]</p>\n<p>@DerekZH -</p>\n<p>Also note, this method doesn't account for the interactions between features. So, if this data set has strong interactions, you wouldn't expect it to do as well as methods that account for the interactions.</p>\n<p>[/quote]</p>\n<p>I appreciate this insight, Inversion. &nbsp;I will try to give the CTR histogram approach another try, just to learn the approach, and make it a candidate for later ensemble. &nbsp;And I will give more thoughts to accounting for feature interactions. &nbsp;</p>\n<p>Thanks again :)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62853,
      "author_name": "herimanitra",
      "author_url": "",
      "post_date": "01/18/2015 06:28:50",
      "content": "<p>In this case, How would you prepare the test set for prediction as It does not contain 'click'</p>\n<p>[quote=inversion;62355]</p>\n<p>Yup. Something like this:</p>\n<p><img src=\"http://i.imgur.com/yF6RS61.png\" alt width=\"140\" height=\"183\"></p>\n<p>You can do it using &quot;brute force&quot; by writing a loop that counts the number of clicks for each feature, divide by the occurrence of each feature, and then replace each feature with that average.</p>\n<p>There are, of course, more elegant ways to do this, which depend on whether you are using Python, R, etc.</p>\n<p>A google search should be able to get you what you need for your specific setup.</p>\n<p>[/quote]</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62854,
      "author_name": "ivanliu1989",
      "author_url": "",
      "post_date": "01/18/2015 08:05:16",
      "content": "<p>@inversion &nbsp;@lewis ml</p>\n<p>Thank lewis and inversion for bringing us the idea and explanation. &nbsp;</p>\n<p>There is one thing I'm still not clear is how do we deal with the null value in dataset?&nbsp;I think it is obviously not a good idea&nbsp;to consider those null values&nbsp;as unseen features in test dataset and allocate a smoothing value to them (eg, 0.25).</p>\n<p>So should we just conclude these null values as a new category and calculate the average CTR for this category, or do we&nbsp;just keep them as null values in dataset?</p>\n<p>Thanks :)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62855,
      "author_name": "cartographic",
      "author_url": "",
      "post_date": "01/18/2015 08:51:51",
      "content": "<p>Herimanitra: you have to build the test set by looking up the relevant ctr from the train set. So with inversion's example, any test case with A gets a 0.75 for that ctr feature.</p>\n<p>Ivan: you raise a good point but I'm not sure there's an &nbsp;obvious 'right' way to deal with the issue. Might be worth trying different treatments.</p>\n<p>inversion: I feel like I'm missing something on your point about interactions. You can add interactions by creating a new categorical feature from two existing features, then calculating the ctr for it. But are saying you wouldn't expect that to be effective?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62860,
      "author_name": "inversion",
      "author_url": "",
      "post_date": "01/18/2015 15:04:38",
      "content": "<p>[quote=lewis ml;62855]</p>\n<p>inversion: I feel like I'm missing something on your point about interactions. You can add interactions by creating a new categorical feature from two existing features, then calculating the ctr for it. But are saying you wouldn't expect that to be effective?</p>\n<p>[/quote]</p>\n<p>You're absolutely right . . . what I was trying to convey was that if you just reduced the feature set&nbsp;<em>as is</em> to average&nbsp;CTRs, you shouldn't necessarily expect a decent score. But there's no reason you couldn't build interactions as you suggest.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62861,
      "author_name": "inversion",
      "author_url": "",
      "post_date": "01/18/2015 15:07:18",
      "content": "<p>[quote=Ivan Liu;62854]</p>\n<p>@inversion &nbsp;@lewis ml</p>\n<p>So should we just conclude these null values as a new category and calculate the average CTR for this category, or do we&nbsp;just keep them as null values in dataset?</p>\n<p>Thanks :)</p>\n<p>[/quote]</p>\n<p>I've tried both ways . . . it's far less a hassle to change nulls to a new categorical feature.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "62321": "",
    "62322": "",
    "62340": "",
    "62355": "",
    "62356": "",
    "62358": "",
    "62359": "",
    "62362": "",
    "62364": "",
    "62366": "",
    "62367": "",
    "62368": "",
    "62380": "",
    "62397": "",
    "62399": "",
    "62406": "",
    "62413": "",
    "62415": "",
    "62485": "",
    "62504": "",
    "62505": "",
    "62580": "",
    "62853": "",
    "62854": "",
    "62855": "",
    "62860": "",
    "62861": ""
  },
  "source": "meta"
}