{
  "id": 26411,
  "title": "My approach",
  "content": "<p>I'm really curious to hear from the rest of the top 10, but I'll go first:</p>\n\n<ol>\n<li>First, I started with the best public script, in particular the XGBoost scripts and keras scripts that were floating around.  Picking the best tuned single model didn't seem to matter a whole lot, e.g. I used one of the the PB LB 1108 XG scripts and never got around to running the 1106 one (maybe that was my mistake!).  I edited most of the keras scripts to run 10 CV folds and 10 bags, and most of the XGBoost scripts to use 10 folds and no bags.</li>\n<li>I modified each public script to generate stacked predictions, if it didn't already.   All the keras script generated stacked predictions, but I had to modify some of the XGBoost scripts to generate stacked predictions.  This was key.</li>\n<li>Next, I generated a bunch of different datasets to run through those scripts.  This was the part where I got a bit creative.  I can go into more detail here later, but I did things like PCA on all the numeric variables, PCA on all the categorical variables, PCA on all the numeric + categorical variables, all the numeric variables differences and ratios, all the categorical variable interactions, etc.</li>\n<li>Steps #2 and #3 were my core loop.  Generate new datasets, and then run them through my XGBoost and Keras scripts to generate stacked predictions and test-set predictions. New datasets usually gave me more lift than tuning my models.</li>\n<li>After a few iterations, I'd end up with a bunch of models with stacked predictions and test-set predictions.  Before any ensembling, I ran these models through wilcox.test in R, to make sure the stacked predictions were similar to the test set predictions.  Anything with a p.value of less than .10 I dropped from my ensemble.  Sometimes this step indicated models where I'd done something silly, like forgetting to un-transform the test-set predictions.</li>\n<li>Then I took the set of remaining stacked predictions, and ran PCA on them.  I added the first PCA component to the stacked predictions and the test set predictions.</li>\n<li>Now for the key step.  I ran the stacked predictions through the optim() function in R, to find linear weights that minimized MAE.  I used the BFGS solver for optim.</li>\n<li>Later in the competition, I split the stacked predictions into thirds, based on the PC1 component, and used optim on each third.  I then applied these 3 sets of weights to the test set, based on the PC1 component for the test set.  I'm not sure if this helped or hurt me at the end of the competition; it may have been unnecessary complexity.</li>\n<li>I also added some L1 regularization to my call to the optim function.  I simple added  mean(abs(w))*(a penalty factor) to the objective function for optimizing the weights.  I'm pretty sure this regularization helped at the end of the competition.</li>\n<li>I made 2 subs at the end: my best leaderboard score, and my best local CV score.  I think my best local CV score ended up being the best on the private LB.  Based on the small shakeup at the end of the competition, I'm happy I made one sub with my best local CV.  Trust your cross-validation!</li>\n</ol>\n\n<p>Once I see the public vs private LB for all my subs, I'll have more details on what helped or what hurt.</p>",
  "comments": [
    {
      "id": 149860,
      "author_name": "Zach",
      "author_url": "",
      "post_date": "2016-12-13T02:57:45.977000",
      "content": "<p>Also, another piece of advice: don't be afraid to be messy.  My final folder for this competition has something like 100 r and python scripts in it.  I basically made a new script for everything I tried.  This made it a lot easier to backtrack when I needed to.</p>\n\n<p>Trying to put every single model you run into one script isn't going to work.  Do one model per script, and do your stacking in another script.</p>\n\n<p>(and use git!)</p>",
      "votes": 9,
      "replies": [
        {
          "id": 149866,
          "author_name": "Vladimir Iglovikov",
          "author_url": "",
          "post_date": "2016-12-13T03:01:43.500000",
          "content": "<p>[quote=Zach;149860]</p>\n\n<p>Trying to put every single model you run into one script isn't going to work.  Do one model per script, and do your stacking in another script.</p>\n\n<p>(and use git!)</p>\n\n<p>[/quote]</p>\n\n<p>Link to the repository? :)</p>",
          "votes": 1,
          "replies": [
            {
              "id": 149874,
              "author_name": "Zach",
              "author_url": "",
              "post_date": "2016-12-13T03:15:03.113000",
              "content": "<p>[quote=Vladimir Iglovikov;149866]\nLink to the repository? :)\n[/quote]</p>\n\n<p>I gotta put it all up on github (was using a local repo).  </p>",
              "votes": 2,
              "replies": []
            }
          ]
        },
        {
          "id": 149869,
          "author_name": "Tilii",
          "author_url": "",
          "post_date": "2016-12-13T03:08:57.097000",
          "content": "<p>[quote=Zach;149860]</p>\n\n<p>Also, another piece of advice: don't be afraid to be messy.  My final folder for this competition has something like 100 r and python scripts in it.  I basically made a new script for everything I tried.  This made it a lot easier to backtrack when I needed to.</p>\n\n<p>Trying to put every single model you run into one script isn't going to work.  Do one model per script, and do your stacking in another script.</p>\n\n<p>(and use git!)</p>\n\n<p>[/quote]</p>\n\n<p>My general approach is the same, except that your \"messy\" is probably a Russian marching line compared to my \"messy.\" Wait, I shouldn't be bragging about this ...</p>\n\n<p>That's why I never could publish a nice post-mortem for this competition like Vladimir did. Props for that, by the way.</p>",
          "votes": 1,
          "replies": [
            {
              "id": 149870,
              "author_name": "Zach",
              "author_url": "",
              "post_date": "2016-12-13T03:11:46.440000",
              "content": "<p>[quote=Tilii;149869]\nMy general approach is the same, except that your \"messy\" is probably a Russian marching line compared to my \"messy.\" Wait, I shouldn't be bragging about this ...\n[/quote]</p>\n\n<p>This is the first book on my holiday reading list, lol: <a href=\"http://timharford.com/books/messy/\">http://timharford.com/books/messy/</a></p>",
              "votes": 1,
              "replies": []
            },
            {
              "id": 149877,
              "author_name": "Tilii",
              "author_url": "",
              "post_date": "2016-12-13T03:20:53.577000",
              "content": "<p>[quote=Zach;149870]</p>\n\n<p>[quote=Tilii;149869]\nMy general approach is the same, except that your \"messy\" is probably a Russian marching line compared to my \"messy.\" Wait, I shouldn't be bragging about this ...\n[/quote]</p>\n\n<p>This is the first book on my holiday reading list, lol: <a href=\"http://timharford.com/books/messy/\">http://timharford.com/books/messy/</a></p>\n\n<p>[/quote]</p>\n\n<p>You just made $20 for Tim Harford. Let's hope I read it before the holidays are over, or else I'll start the New Year with my guilt undiminished over the state of my garage, basement, office ...</p>",
              "votes": 2,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 149863,
      "author_name": "Zach",
      "author_url": "",
      "post_date": "2016-12-13T02:58:55.620000",
      "content": "<p>Also, I let my weights go negative. I think since all my models were so highly correlated, allowing negative weights allowed the optimizer to find a better solution.</p>",
      "votes": 3,
      "replies": []
    },
    {
      "id": 149846,
      "author_name": "Vladimir Iglovikov",
      "author_url": "",
      "post_date": "2016-12-13T02:03:05.567000",
      "content": "<ol>\n<li>Just to verify, only models that you used are xgb and NN?    </li>\n<li>Do you have statistics on how different version of the dataset affected first level model performance?</li>\n<li>What is your best final CV score?</li>\n<li>Did you come to this idea of using PCA during stacking in this competition or it is based on the previous experience with some other problem that I can read about? </li>\n</ol>",
      "votes": 3,
      "replies": [
        {
          "id": 149851,
          "author_name": "Zach",
          "author_url": "",
          "post_date": "2016-12-13T02:30:07.790000",
          "content": "<p>[quote=Vladimir Iglovikov;149846]</p>\n\n<ol>\n<li>Just to verify, only models that you used are xgb and NN?    </li>\n<li>Do you have statistics on how different version of the dataset affected first level model performance?</li>\n<li>What is your best final CV score?</li>\n<li>Did you come to this idea of using PCA during stacking in this competition or it is based on the previous experience with some other problem that I can read about? </li>\n</ol>\n\n<p>[/quote]</p>\n\n<ol>\n<li>I also ran some glmnet models on some of my datasets, but I think 95% of my score was XGB and keras scripts.</li>\n<li>I don't.  Many of my datasets gave worst first level models but still helped the ensemble.</li>\n<li>1115.2134 +/- 8.9</li>\n<li>I thought that doing PCA, and then optimizing on the PCA components would help the BFGS solver.  It didn't.  But then adding the first PCA component to the mix did, so I kept that.</li>\n</ol>\n\n<p>/edit: changed 90% to 95%.  I relied pretty heavily on XGB + keras, but I did tweak the keras scripts (e.g. adding highway layers to some).</p>",
          "votes": 3,
          "replies": []
        }
      ]
    },
    {
      "id": 149845,
      "author_name": "Zach",
      "author_url": "",
      "post_date": "2016-12-13T02:02:03.763000",
      "content": "<p>One follow up: I started with a simple stacking model: BFGS to find the weights that minimize MAE. I then slowly made that stack more complicated, first by adding the PC1 component, then by adding L1 regularization, and finally splitting into thirds based on the first PC component.</p>",
      "votes": 3,
      "replies": []
    },
    {
      "id": 150037,
      "author_name": "Ben Gorman",
      "author_url": "",
      "post_date": "2016-12-13T16:51:05.027000",
      "content": "<p>Congrats on making it to Grand Master, Zach!</p>\n\n<p>What kind of hardware setup did you use?  I entered the competition late with the expectation of running everything on my laptop - bad idea.  Trying to decide if I should learn AWS, another cloud service, or just buy a second machine for running models that take hours to train.</p>",
      "votes": 1,
      "replies": [
        {
          "id": 150044,
          "author_name": "Zach",
          "author_url": "",
          "post_date": "2016-12-13T17:16:05.377000",
          "content": "<p>[quote=Ben Gorman;150037]</p>\n\n<p>Congrats on making it to Grand Master, Zach!</p>\n\n<p>What kind of hardware setup did you use?  I entered the competition late with the expectation of running everything on my laptop - bad idea.  Trying to decide if I should learn AWS, another cloud service, or just buy a second machine for running models that take hours to train.</p>\n\n<p>[/quote]</p>\n\n<p>Thanks!  I did all my data prep and ran all my ensembles on my 2 year old macbook pro, with a core i7 processor and 16 GB of RAM. <a href=\"http://arstechnica.com/apple/2013/10/os-x-10-9/17/\">Macs have really good memory management</a>, and I've been really happy with this laptop for kaggle (unfortunately it has an AMD, rather than NVIDIA GPU).</p>\n\n<p>I also ran a lot of XGBoost models on my laptop.</p>\n\n<p>For the keras models, I ran them on a workstation with an NVIDIA GPU, which I also used to run a bunch of variants of XGBoost towards the end of the competition.</p>",
          "votes": 2,
          "replies": []
        }
      ]
    },
    {
      "id": 149997,
      "author_name": "Zach",
      "author_url": "",
      "post_date": "2016-12-13T13:42:35.467000",
      "content": "<p>Also, one more follow up!  Trust your local CV!  I make 2 subs at the end, my best local CV, and my best public LB.  The best public LB did a lot worse on the private LB, while my local CV still did pretty well.</p>\n\n<p>In hindsight, when my local CV started to diverge from the public LB, I should have stopped looking at the LB.</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 149852,
      "author_name": "Zach",
      "author_url": "",
      "post_date": "2016-12-13T02:30:58.897000",
      "content": "<p>Also, I played around with some of the keras scripts to generate new models.  One thing that I think helped a little was adding ~20 highway layers after the 3 layer public script.  Again, this model itself was worse on the LB, but contributed to my blend.</p>",
      "votes": 1,
      "replies": [
        {
          "id": 149889,
          "author_name": "SkyLibrary",
          "author_url": "",
          "post_date": "2016-12-13T04:21:23.527000",
          "content": "<p>Thanks for sharing, never thought about using highway layers myself...\nCongrats on becoming grandmaster!</p>\n\n<p>[quote=Zach;149852]</p>\n\n<p>Also, I played around with some of the keras scripts to generate new models.  One thing that I think helped a little was adding ~20 highway layers after the 3 layer public script.  Again, this model itself was worse on the LB, but contributed to my blend.</p>\n\n<p>[/quote]</p>",
          "votes": 2,
          "replies": [
            {
              "id": 149998,
              "author_name": "Zach",
              "author_url": "",
              "post_date": "2016-12-13T13:43:07.920000",
              "content": "<p>[quote=SkyLibrary;149889]\nCongrats on becoming grandmaster!\n[/quote]</p>\n\n<p>Thanks!</p>",
              "votes": 3,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 149854,
      "author_name": "Zach",
      "author_url": "",
      "post_date": "2016-12-13T02:37:20.203000",
      "content": "<p>Also, I think what got me to #4 was \"lots of (diverse) models\" + \"BFGS on the stacked predictions.\"  Everything else is probably noise.</p>",
      "votes": 2,
      "replies": []
    },
    {
      "id": 150124,
      "author_name": "Yang Yang",
      "author_url": "",
      "post_date": "2016-12-13T23:37:51.233000",
      "content": "<p>Sorry for the bad question and thank you again!</p>\n\n<p>Never thought using PCA in this way , learned a lot!</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 150067,
      "author_name": "Yang Yang",
      "author_url": "",
      "post_date": "2016-12-13T18:13:45.530000",
      "content": "<p>Congratz! I  really  learned a lot from you.</p>\n\n<p>Will you explain a little bit of the rationale of why you heavily used PCA in this competition (generate new date set &amp; 1st PC used in ensembling etc ) rather than try other different models in the first level?</p>\n\n<p>I thought using dimension reduction like PCA will lose information and it's better not to use it if not for the limit of computational capability.( i am new with it  :)</p>\n\n<p>Thank you</p>",
      "votes": 0,
      "replies": [
        {
          "id": 150072,
          "author_name": "Zach",
          "author_url": "",
          "post_date": "2016-12-13T18:46:08.207000",
          "content": "<p>[quote=Yang Yang;150067]</p>\n\n<p>Congratz! I  really  learned a lot from you.</p>\n\n<p>Will you explain a little bit of the rationale of why you heavily used PCA in this competition (generate new date set &amp; 1st PC used in ensembling etc ) rather than try other different models in the first level?</p>\n\n<p>I thought using dimension reduction like PCA will lose information and it's better not to use it if not for the limit of computational capability.( i am new with it  :)</p>\n\n<p>Thank you</p>\n\n<p>[/quote]</p>\n\n<p>I really only used PCA to add diversity to my level 1 models. (I wouldn't call it heavy usage).  So most of my models were on the raw data.  Some of my models were on the PCA transformed data.  Some of my models were on the raw data + PCA variables, etc.</p>\n\n<p>PCA is a different way of representing the data, so you get a different model.  Even if you lose information, the new model can contribute to your ensemble.</p>\n\n<p>Using it in ensembling is a red herring.  I don't think adding the PC1 component to my ensemble made much of a difference.  The optimizer mostly used the model's stacked predicitons</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 150048,
      "author_name": "Zach",
      "author_url": "",
      "post_date": "2016-12-13T17:21:08.467000",
      "content": "<p>If you buy a workstation, I'd say you want these things, in this order:</p>\n\n<ol>\n<li>A NVIDIA GPU for keras (even an older one.  An old GPU can give you 5x-10x speedup for keras models)</li>\n<li>Lots of RAM</li>\n<li>Many processors for XGBoost (4 old processors is better than one new)</li>\n<li>An SSD for faster data loading </li>\n</ol>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 150028,
      "author_name": "RickyTall",
      "author_url": "",
      "post_date": "2016-12-13T16:04:35.310000",
      "content": "<p>Hi Zach, </p>\n\n<p>Congratulations on an impressive result.  At a lot of your steps, I found myself asking 'why?'  Then that lead me to the question 'how much of this could be automated?'</p>\n\n<p>Ps.  My brother graduated from Dartmouth in Econ.  </p>",
      "votes": 0,
      "replies": [
        {
          "id": 150030,
          "author_name": "Zach",
          "author_url": "",
          "post_date": "2016-12-13T16:13:03.050000",
          "content": "<p>[quote=RickyTall;150028]\n'how much of this could be automated?'\n[/quote]</p>\n\n<p>I work for a company that tries to automate most of these steps :-D</p>",
          "votes": 3,
          "replies": []
        }
      ]
    },
    {
      "id": 149850,
      "author_name": "Yizhi",
      "author_url": "",
      "post_date": "2016-12-13T02:28:38.400000",
      "content": "<p>What does step6 mean? And how many stacked predictions you got for ensemble? Thanks.</p>",
      "votes": 0,
      "replies": [
        {
          "id": 149853,
          "author_name": "Zach",
          "author_url": "",
          "post_date": "2016-12-13T02:32:49.190000",
          "content": "<p>[quote=Yizhi Tao;149850]</p>\n\n<p>What does step6 mean? And how many stacked predictions you got for ensemble? Thanks.</p>\n\n<p>[/quote]</p>\n\n<p>I did PCA on the stacked predicitons, and then added the first principle component to the stacked predictions before optimizing.  I had 59 models in my final blend + the first PC component of those models.</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 149847,
      "author_name": "modkzs",
      "author_url": "",
      "post_date": "2016-12-13T02:04:51.620000",
      "content": "<p>Could you explain what's PC1?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 149848,
          "author_name": "Vladimir Iglovikov",
          "author_url": "",
          "post_date": "2016-12-13T02:05:44.247000",
          "content": "<p>[quote=modkzs;149847]</p>\n\n<p>Could you explain what's PC1?</p>\n\n<p>[/quote]\nFirst principal component?</p>",
          "votes": 1,
          "replies": []
        }
      ]
    }
  ],
  "comment_count": 27,
  "messages": [
    {
      "id": 149844,
      "postDate": "2016-12-13T01:57:04.980Z",
      "content": "<p>I'm really curious to hear from the rest of the top 10, but I'll go first:</p>\n\n<ol>\n<li>First, I started with the best public script, in particular the XGBoost scripts and keras scripts that were floating around.  Picking the best tuned single model didn't seem to matter a whole lot, e.g. I used one of the the PB LB 1108 XG scripts and never got around to running the 1106 one (maybe that was my mistake!).  I edited most of the keras scripts to run 10 CV folds and 10 bags, and most of the XGBoost scripts to use 10 folds and no bags.</li>\n<li>I modified each public script to generate stacked predictions, if it didn't already.   All the keras script generated stacked predictions, but I had to modify some of the XGBoost scripts to generate stacked predictions.  This was key.</li>\n<li>Next, I generated a bunch of different datasets to run through those scripts.  This was the part where I got a bit creative.  I can go into more detail here later, but I did things like PCA on all the numeric variables, PCA on all the categorical variables, PCA on all the numeric + categorical variables, all the numeric variables differences and ratios, all the categorical variable interactions, etc.</li>\n<li>Steps #2 and #3 were my core loop.  Generate new datasets, and then run them through my XGBoost and Keras scripts to generate stacked predictions and test-set predictions. New datasets usually gave me more lift than tuning my models.</li>\n<li>After a few iterations, I'd end up with a bunch of models with stacked predictions and test-set predictions.  Before any ensembling, I ran these models through wilcox.test in R, to make sure the stacked predictions were similar to the test set predictions.  Anything with a p.value of less than .10 I dropped from my ensemble.  Sometimes this step indicated models where I'd done something silly, like forgetting to un-transform the test-set predictions.</li>\n<li>Then I took the set of remaining stacked predictions, and ran PCA on them.  I added the first PCA component to the stacked predictions and the test set predictions.</li>\n<li>Now for the key step.  I ran the stacked predictions through the optim() function in R, to find linear weights that minimized MAE.  I used the BFGS solver for optim.</li>\n<li>Later in the competition, I split the stacked predictions into thirds, based on the PC1 component, and used optim on each third.  I then applied these 3 sets of weights to the test set, based on the PC1 component for the test set.  I'm not sure if this helped or hurt me at the end of the competition; it may have been unnecessary complexity.</li>\n<li>I also added some L1 regularization to my call to the optim function.  I simple added  mean(abs(w))*(a penalty factor) to the objective function for optimizing the weights.  I'm pretty sure this regularization helped at the end of the competition.</li>\n<li>I made 2 subs at the end: my best leaderboard score, and my best local CV score.  I think my best local CV score ended up being the best on the private LB.  Based on the small shakeup at the end of the competition, I'm happy I made one sub with my best local CV.  Trust your cross-validation!</li>\n</ol>\n\n<p>Once I see the public vs private LB for all my subs, I'll have more details on what helped or what hurt.</p>",
      "rawMarkdown": "I'm really curious to hear from the rest of the top 10, but I'll go first:\r\n\r\n1. First, I started with the best public script, in particular the XGBoost scripts and keras scripts that were floating around.  Picking the best tuned single model didn't seem to matter a whole lot, e.g. I used one of the the PB LB 1108 XG scripts and never got around to running the 1106 one (maybe that was my mistake!).  I edited most of the keras scripts to run 10 CV folds and 10 bags, and most of the XGBoost scripts to use 10 folds and no bags.\r\n2. I modified each public script to generate stacked predictions, if it didn't already.   All the keras script generated stacked predictions, but I had to modify some of the XGBoost scripts to generate stacked predictions.  This was key.\r\n3. Next, I generated a bunch of different datasets to run through those scripts.  This was the part where I got a bit creative.  I can go into more detail here later, but I did things like PCA on all the numeric variables, PCA on all the categorical variables, PCA on all the numeric + categorical variables, all the numeric variables differences and ratios, all the categorical variable interactions, etc.\r\n4. Steps #2 and #3 were my core loop.  Generate new datasets, and then run them through my XGBoost and Keras scripts to generate stacked predictions and test-set predictions. New datasets usually gave me more lift than tuning my models.\r\n5. After a few iterations, I'd end up with a bunch of models with stacked predictions and test-set predictions.  Before any ensembling, I ran these models through wilcox.test in R, to make sure the stacked predictions were similar to the test set predictions.  Anything with a p.value of less than .10 I dropped from my ensemble.  Sometimes this step indicated models where I'd done something silly, like forgetting to un-transform the test-set predictions.\r\n6. Then I took the set of remaining stacked predictions, and ran PCA on them.  I added the first PCA component to the stacked predictions and the test set predictions.\r\n7.  Now for the key step.  I ran the stacked predictions through the optim() function in R, to find linear weights that minimized MAE.  I used the BFGS solver for optim.\r\n8. Later in the competition, I split the stacked predictions into thirds, based on the PC1 component, and used optim on each third.  I then applied these 3 sets of weights to the test set, based on the PC1 component for the test set.  I'm not sure if this helped or hurt me at the end of the competition; it may have been unnecessary complexity.\r\n9. I also added some L1 regularization to my call to the optim function.  I simple added  mean(abs(w))*(a penalty factor) to the objective function for optimizing the weights.  I'm pretty sure this regularization helped at the end of the competition.\r\n10. I made 2 subs at the end: my best leaderboard score, and my best local CV score.  I think my best local CV score ended up being the best on the private LB.  Based on the small shakeup at the end of the competition, I'm happy I made one sub with my best local CV.  Trust your cross-validation!\r\n \r\nOnce I see the public vs private LB for all my subs, I'll have more details on what helped or what hurt.",
      "votes": 50
    },
    {
      "id": 149860,
      "postDate": "2016-12-13T02:57:45.977Z",
      "content": "<p>Also, another piece of advice: don't be afraid to be messy.  My final folder for this competition has something like 100 r and python scripts in it.  I basically made a new script for everything I tried.  This made it a lot easier to backtrack when I needed to.</p>\n\n<p>Trying to put every single model you run into one script isn't going to work.  Do one model per script, and do your stacking in another script.</p>\n\n<p>(and use git!)</p>",
      "rawMarkdown": "Also, another piece of advice: don't be afraid to be messy.  My final folder for this competition has something like 100 r and python scripts in it.  I basically made a new script for everything I tried.  This made it a lot easier to backtrack when I needed to.\r\n\r\nTrying to put every single model you run into one script isn't going to work.  Do one model per script, and do your stacking in another script.\r\n\r\n(and use git!)",
      "votes": 9,
      "replies": [
        {
          "id": 149866,
          "postDate": "2016-12-13T03:01:43.500Z",
          "content": "<p>[quote=Zach;149860]</p>\n\n<p>Trying to put every single model you run into one script isn't going to work.  Do one model per script, and do your stacking in another script.</p>\n\n<p>(and use git!)</p>\n\n<p>[/quote]</p>\n\n<p>Link to the repository? :)</p>",
          "rawMarkdown": "[quote=Zach;149860]\r\n\r\nTrying to put every single model you run into one script isn't going to work.  Do one model per script, and do your stacking in another script.\r\n\r\n(and use git!)\r\n\r\n[/quote]\r\n\r\nLink to the repository? :)",
          "votes": 1,
          "replies": [
            {
              "id": 149874,
              "postDate": "2016-12-13T03:15:03.113Z",
              "content": "<p>[quote=Vladimir Iglovikov;149866]\nLink to the repository? :)\n[/quote]</p>\n\n<p>I gotta put it all up on github (was using a local repo).  </p>",
              "rawMarkdown": "[quote=Vladimir Iglovikov;149866]\r\nLink to the repository? :)\r\n[/quote]\r\n\r\nI gotta put it all up on github (was using a local repo).  \r\n",
              "votes": 2
            }
          ]
        },
        {
          "id": 149869,
          "postDate": "2016-12-13T03:08:57.097Z",
          "content": "<p>[quote=Zach;149860]</p>\n\n<p>Also, another piece of advice: don't be afraid to be messy.  My final folder for this competition has something like 100 r and python scripts in it.  I basically made a new script for everything I tried.  This made it a lot easier to backtrack when I needed to.</p>\n\n<p>Trying to put every single model you run into one script isn't going to work.  Do one model per script, and do your stacking in another script.</p>\n\n<p>(and use git!)</p>\n\n<p>[/quote]</p>\n\n<p>My general approach is the same, except that your \"messy\" is probably a Russian marching line compared to my \"messy.\" Wait, I shouldn't be bragging about this ...</p>\n\n<p>That's why I never could publish a nice post-mortem for this competition like Vladimir did. Props for that, by the way.</p>",
          "rawMarkdown": "[quote=Zach;149860]\r\n\r\nAlso, another piece of advice: don't be afraid to be messy.  My final folder for this competition has something like 100 r and python scripts in it.  I basically made a new script for everything I tried.  This made it a lot easier to backtrack when I needed to.\r\n\r\nTrying to put every single model you run into one script isn't going to work.  Do one model per script, and do your stacking in another script.\r\n\r\n(and use git!)\r\n\r\n[/quote]\r\n\r\nMy general approach is the same, except that your \"messy\" is probably a Russian marching line compared to my \"messy.\" Wait, I shouldn't be bragging about this ...\r\n\r\nThat's why I never could publish a nice post-mortem for this competition like Vladimir did. Props for that, by the way.\r\n",
          "votes": 1,
          "replies": [
            {
              "id": 149870,
              "postDate": "2016-12-13T03:11:46.440Z",
              "content": "<p>[quote=Tilii;149869]\nMy general approach is the same, except that your \"messy\" is probably a Russian marching line compared to my \"messy.\" Wait, I shouldn't be bragging about this ...\n[/quote]</p>\n\n<p>This is the first book on my holiday reading list, lol: <a href=\"http://timharford.com/books/messy/\">http://timharford.com/books/messy/</a></p>",
              "rawMarkdown": "[quote=Tilii;149869]\r\nMy general approach is the same, except that your \"messy\" is probably a Russian marching line compared to my \"messy.\" Wait, I shouldn't be bragging about this ...\r\n[/quote]\r\n\r\nThis is the first book on my holiday reading list, lol: http://timharford.com/books/messy/",
              "votes": 1
            },
            {
              "id": 149877,
              "postDate": "2016-12-13T03:20:53.577Z",
              "content": "<p>[quote=Zach;149870]</p>\n\n<p>[quote=Tilii;149869]\nMy general approach is the same, except that your \"messy\" is probably a Russian marching line compared to my \"messy.\" Wait, I shouldn't be bragging about this ...\n[/quote]</p>\n\n<p>This is the first book on my holiday reading list, lol: <a href=\"http://timharford.com/books/messy/\">http://timharford.com/books/messy/</a></p>\n\n<p>[/quote]</p>\n\n<p>You just made $20 for Tim Harford. Let's hope I read it before the holidays are over, or else I'll start the New Year with my guilt undiminished over the state of my garage, basement, office ...</p>",
              "rawMarkdown": "[quote=Zach;149870]\r\n\r\n[quote=Tilii;149869]\r\nMy general approach is the same, except that your \"messy\" is probably a Russian marching line compared to my \"messy.\" Wait, I shouldn't be bragging about this ...\r\n[/quote]\r\n\r\nThis is the first book on my holiday reading list, lol: http://timharford.com/books/messy/\r\n\r\n[/quote]\r\n\r\nYou just made $20 for Tim Harford. Let's hope I read it before the holidays are over, or else I'll start the New Year with my guilt undiminished over the state of my garage, basement, office ...\r\n",
              "votes": 2
            }
          ]
        }
      ]
    },
    {
      "id": 149863,
      "postDate": "2016-12-13T02:58:55.620Z",
      "content": "<p>Also, I let my weights go negative. I think since all my models were so highly correlated, allowing negative weights allowed the optimizer to find a better solution.</p>",
      "rawMarkdown": "Also, I let my weights go negative. I think since all my models were so highly correlated, allowing negative weights allowed the optimizer to find a better solution.",
      "votes": 3
    },
    {
      "id": 149846,
      "postDate": "2016-12-13T02:03:05.567Z",
      "content": "<ol>\n<li>Just to verify, only models that you used are xgb and NN?    </li>\n<li>Do you have statistics on how different version of the dataset affected first level model performance?</li>\n<li>What is your best final CV score?</li>\n<li>Did you come to this idea of using PCA during stacking in this competition or it is based on the previous experience with some other problem that I can read about? </li>\n</ol>",
      "rawMarkdown": " 1. Just to verify, only models that you used are xgb and NN?    \r\n 2. Do you have statistics on how different version of the dataset affected first level model performance?\r\n 3. What is your best final CV score?\r\n 4. Did you come to this idea of using PCA during stacking in this competition or it is based on the previous experience with some other problem that I can read about? ",
      "votes": 3,
      "replies": [
        {
          "id": 149851,
          "postDate": "2016-12-13T02:30:07.790Z",
          "content": "<p>[quote=Vladimir Iglovikov;149846]</p>\n\n<ol>\n<li>Just to verify, only models that you used are xgb and NN?    </li>\n<li>Do you have statistics on how different version of the dataset affected first level model performance?</li>\n<li>What is your best final CV score?</li>\n<li>Did you come to this idea of using PCA during stacking in this competition or it is based on the previous experience with some other problem that I can read about? </li>\n</ol>\n\n<p>[/quote]</p>\n\n<ol>\n<li>I also ran some glmnet models on some of my datasets, but I think 95% of my score was XGB and keras scripts.</li>\n<li>I don't.  Many of my datasets gave worst first level models but still helped the ensemble.</li>\n<li>1115.2134 +/- 8.9</li>\n<li>I thought that doing PCA, and then optimizing on the PCA components would help the BFGS solver.  It didn't.  But then adding the first PCA component to the mix did, so I kept that.</li>\n</ol>\n\n<p>/edit: changed 90% to 95%.  I relied pretty heavily on XGB + keras, but I did tweak the keras scripts (e.g. adding highway layers to some).</p>",
          "rawMarkdown": "[quote=Vladimir Iglovikov;149846]\r\n\r\n 1. Just to verify, only models that you used are xgb and NN?    \r\n 2. Do you have statistics on how different version of the dataset affected first level model performance?\r\n 3. What is your best final CV score?\r\n 4. Did you come to this idea of using PCA during stacking in this competition or it is based on the previous experience with some other problem that I can read about? \r\n\r\n[/quote]\r\n\r\n1.  I also ran some glmnet models on some of my datasets, but I think 95% of my score was XGB and keras scripts.\r\n2. I don't.  Many of my datasets gave worst first level models but still helped the ensemble.\r\n3. 1115.2134 +/- 8.9\r\n4. I thought that doing PCA, and then optimizing on the PCA components would help the BFGS solver.  It didn't.  But then adding the first PCA component to the mix did, so I kept that.\r\n\r\n/edit: changed 90% to 95%.  I relied pretty heavily on XGB + keras, but I did tweak the keras scripts (e.g. adding highway layers to some).\r\n",
          "votes": 3
        }
      ]
    },
    {
      "id": 149845,
      "postDate": "2016-12-13T02:02:03.763Z",
      "content": "<p>One follow up: I started with a simple stacking model: BFGS to find the weights that minimize MAE. I then slowly made that stack more complicated, first by adding the PC1 component, then by adding L1 regularization, and finally splitting into thirds based on the first PC component.</p>",
      "rawMarkdown": "One follow up: I started with a simple stacking model: BFGS to find the weights that minimize MAE. I then slowly made that stack more complicated, first by adding the PC1 component, then by adding L1 regularization, and finally splitting into thirds based on the first PC component.",
      "votes": 3
    },
    {
      "id": 150037,
      "postDate": "2016-12-13T16:51:05.027Z",
      "content": "<p>Congrats on making it to Grand Master, Zach!</p>\n\n<p>What kind of hardware setup did you use?  I entered the competition late with the expectation of running everything on my laptop - bad idea.  Trying to decide if I should learn AWS, another cloud service, or just buy a second machine for running models that take hours to train.</p>",
      "rawMarkdown": "Congrats on making it to Grand Master, Zach!\r\n\r\nWhat kind of hardware setup did you use?  I entered the competition late with the expectation of running everything on my laptop - bad idea.  Trying to decide if I should learn AWS, another cloud service, or just buy a second machine for running models that take hours to train.",
      "votes": 1,
      "replies": [
        {
          "id": 150044,
          "postDate": "2016-12-13T17:16:05.377Z",
          "content": "<p>[quote=Ben Gorman;150037]</p>\n\n<p>Congrats on making it to Grand Master, Zach!</p>\n\n<p>What kind of hardware setup did you use?  I entered the competition late with the expectation of running everything on my laptop - bad idea.  Trying to decide if I should learn AWS, another cloud service, or just buy a second machine for running models that take hours to train.</p>\n\n<p>[/quote]</p>\n\n<p>Thanks!  I did all my data prep and ran all my ensembles on my 2 year old macbook pro, with a core i7 processor and 16 GB of RAM. <a href=\"http://arstechnica.com/apple/2013/10/os-x-10-9/17/\">Macs have really good memory management</a>, and I've been really happy with this laptop for kaggle (unfortunately it has an AMD, rather than NVIDIA GPU).</p>\n\n<p>I also ran a lot of XGBoost models on my laptop.</p>\n\n<p>For the keras models, I ran them on a workstation with an NVIDIA GPU, which I also used to run a bunch of variants of XGBoost towards the end of the competition.</p>",
          "rawMarkdown": "[quote=Ben Gorman;150037]\r\n\r\nCongrats on making it to Grand Master, Zach!\r\n\r\nWhat kind of hardware setup did you use?  I entered the competition late with the expectation of running everything on my laptop - bad idea.  Trying to decide if I should learn AWS, another cloud service, or just buy a second machine for running models that take hours to train.\r\n\r\n[/quote]\r\n\r\nThanks!  I did all my data prep and ran all my ensembles on my 2 year old macbook pro, with a core i7 processor and 16 GB of RAM. [Macs have really good memory management][1], and I've been really happy with this laptop for kaggle (unfortunately it has an AMD, rather than NVIDIA GPU).\r\n\r\nI also ran a lot of XGBoost models on my laptop.\r\n\r\nFor the keras models, I ran them on a workstation with an NVIDIA GPU, which I also used to run a bunch of variants of XGBoost towards the end of the competition.\r\n\r\n\r\n\r\n\r\n  [1]: http://arstechnica.com/apple/2013/10/os-x-10-9/17/",
          "votes": 2
        }
      ]
    },
    {
      "id": 149997,
      "postDate": "2016-12-13T13:42:35.467Z",
      "content": "<p>Also, one more follow up!  Trust your local CV!  I make 2 subs at the end, my best local CV, and my best public LB.  The best public LB did a lot worse on the private LB, while my local CV still did pretty well.</p>\n\n<p>In hindsight, when my local CV started to diverge from the public LB, I should have stopped looking at the LB.</p>",
      "rawMarkdown": "Also, one more follow up!  Trust your local CV!  I make 2 subs at the end, my best local CV, and my best public LB.  The best public LB did a lot worse on the private LB, while my local CV still did pretty well.\r\n\r\nIn hindsight, when my local CV started to diverge from the public LB, I should have stopped looking at the LB.",
      "votes": 1
    },
    {
      "id": 149852,
      "postDate": "2016-12-13T02:30:58.897Z",
      "content": "<p>Also, I played around with some of the keras scripts to generate new models.  One thing that I think helped a little was adding ~20 highway layers after the 3 layer public script.  Again, this model itself was worse on the LB, but contributed to my blend.</p>",
      "rawMarkdown": "Also, I played around with some of the keras scripts to generate new models.  One thing that I think helped a little was adding ~20 highway layers after the 3 layer public script.  Again, this model itself was worse on the LB, but contributed to my blend.",
      "votes": 1,
      "replies": [
        {
          "id": 149889,
          "postDate": "2016-12-13T04:21:23.527Z",
          "content": "<p>Thanks for sharing, never thought about using highway layers myself...\nCongrats on becoming grandmaster!</p>\n\n<p>[quote=Zach;149852]</p>\n\n<p>Also, I played around with some of the keras scripts to generate new models.  One thing that I think helped a little was adding ~20 highway layers after the 3 layer public script.  Again, this model itself was worse on the LB, but contributed to my blend.</p>\n\n<p>[/quote]</p>",
          "rawMarkdown": "Thanks for sharing, never thought about using highway layers myself...\r\nCongrats on becoming grandmaster!\r\n\r\n[quote=Zach;149852]\r\n\r\nAlso, I played around with some of the keras scripts to generate new models.  One thing that I think helped a little was adding ~20 highway layers after the 3 layer public script.  Again, this model itself was worse on the LB, but contributed to my blend.\r\n\r\n[/quote]\r\n\r\n",
          "votes": 2,
          "replies": [
            {
              "id": 149998,
              "postDate": "2016-12-13T13:43:07.920Z",
              "content": "<p>[quote=SkyLibrary;149889]\nCongrats on becoming grandmaster!\n[/quote]</p>\n\n<p>Thanks!</p>",
              "rawMarkdown": "[quote=SkyLibrary;149889]\r\nCongrats on becoming grandmaster!\r\n[/quote]\r\n\r\nThanks!",
              "votes": 3
            }
          ]
        }
      ]
    },
    {
      "id": 149854,
      "postDate": "2016-12-13T02:37:20.203Z",
      "content": "<p>Also, I think what got me to #4 was \"lots of (diverse) models\" + \"BFGS on the stacked predictions.\"  Everything else is probably noise.</p>",
      "rawMarkdown": "Also, I think what got me to #4 was \"lots of (diverse) models\" + \"BFGS on the stacked predictions.\"  Everything else is probably noise.",
      "votes": 2
    },
    {
      "id": 150124,
      "postDate": "2016-12-13T23:37:51.233Z",
      "content": "<p>Sorry for the bad question and thank you again!</p>\n\n<p>Never thought using PCA in this way , learned a lot!</p>",
      "rawMarkdown": "Sorry for the bad question and thank you again!\r\n\r\nNever thought using PCA in this way , learned a lot!"
    },
    {
      "id": 150067,
      "postDate": "2016-12-13T18:13:45.530Z",
      "content": "<p>Congratz! I  really  learned a lot from you.</p>\n\n<p>Will you explain a little bit of the rationale of why you heavily used PCA in this competition (generate new date set &amp; 1st PC used in ensembling etc ) rather than try other different models in the first level?</p>\n\n<p>I thought using dimension reduction like PCA will lose information and it's better not to use it if not for the limit of computational capability.( i am new with it  :)</p>\n\n<p>Thank you</p>",
      "rawMarkdown": "Congratz! I  really  learned a lot from you.\r\n\r\nWill you explain a little bit of the rationale of why you heavily used PCA in this competition (generate new date set & 1st PC used in ensembling etc ) rather than try other different models in the first level?\r\n\r\nI thought using dimension reduction like PCA will lose information and it's better not to use it if not for the limit of computational capability.( i am new with it  :)\r\n\r\nThank you",
      "replies": [
        {
          "id": 150072,
          "postDate": "2016-12-13T18:46:08.207Z",
          "content": "<p>[quote=Yang Yang;150067]</p>\n\n<p>Congratz! I  really  learned a lot from you.</p>\n\n<p>Will you explain a little bit of the rationale of why you heavily used PCA in this competition (generate new date set &amp; 1st PC used in ensembling etc ) rather than try other different models in the first level?</p>\n\n<p>I thought using dimension reduction like PCA will lose information and it's better not to use it if not for the limit of computational capability.( i am new with it  :)</p>\n\n<p>Thank you</p>\n\n<p>[/quote]</p>\n\n<p>I really only used PCA to add diversity to my level 1 models. (I wouldn't call it heavy usage).  So most of my models were on the raw data.  Some of my models were on the PCA transformed data.  Some of my models were on the raw data + PCA variables, etc.</p>\n\n<p>PCA is a different way of representing the data, so you get a different model.  Even if you lose information, the new model can contribute to your ensemble.</p>\n\n<p>Using it in ensembling is a red herring.  I don't think adding the PC1 component to my ensemble made much of a difference.  The optimizer mostly used the model's stacked predicitons</p>",
          "rawMarkdown": "[quote=Yang Yang;150067]\r\n\r\nCongratz! I  really  learned a lot from you.\r\n\r\nWill you explain a little bit of the rationale of why you heavily used PCA in this competition (generate new date set & 1st PC used in ensembling etc ) rather than try other different models in the first level?\r\n\r\nI thought using dimension reduction like PCA will lose information and it's better not to use it if not for the limit of computational capability.( i am new with it  :)\r\n\r\nThank you\r\n\r\n[/quote]\r\n\r\nI really only used PCA to add diversity to my level 1 models. (I wouldn't call it heavy usage).  So most of my models were on the raw data.  Some of my models were on the PCA transformed data.  Some of my models were on the raw data + PCA variables, etc.\r\n\r\nPCA is a different way of representing the data, so you get a different model.  Even if you lose information, the new model can contribute to your ensemble.\r\n\r\nUsing it in ensembling is a red herring.  I don't think adding the PC1 component to my ensemble made much of a difference.  The optimizer mostly used the model's stacked predicitons",
          "votes": 1
        }
      ]
    },
    {
      "id": 150048,
      "postDate": "2016-12-13T17:21:08.467Z",
      "content": "<p>If you buy a workstation, I'd say you want these things, in this order:</p>\n\n<ol>\n<li>A NVIDIA GPU for keras (even an older one.  An old GPU can give you 5x-10x speedup for keras models)</li>\n<li>Lots of RAM</li>\n<li>Many processors for XGBoost (4 old processors is better than one new)</li>\n<li>An SSD for faster data loading </li>\n</ol>",
      "rawMarkdown": "If you buy a workstation, I'd say you want these things, in this order:\r\n\r\n1. A NVIDIA GPU for keras (even an older one.  An old GPU can give you 5x-10x speedup for keras models)\r\n2. Lots of RAM\r\n3. Many processors for XGBoost (4 old processors is better than one new)\r\n4. An SSD for faster data loading \r\n"
    },
    {
      "id": 150028,
      "postDate": "2016-12-13T16:04:35.310Z",
      "content": "<p>Hi Zach, </p>\n\n<p>Congratulations on an impressive result.  At a lot of your steps, I found myself asking 'why?'  Then that lead me to the question 'how much of this could be automated?'</p>\n\n<p>Ps.  My brother graduated from Dartmouth in Econ.  </p>",
      "rawMarkdown": "Hi Zach, \r\n\r\nCongratulations on an impressive result.  At a lot of your steps, I found myself asking 'why?'  Then that lead me to the question 'how much of this could be automated?'\r\n\r\nPs.  My brother graduated from Dartmouth in Econ.  ",
      "replies": [
        {
          "id": 150030,
          "postDate": "2016-12-13T16:13:03.050Z",
          "content": "<p>[quote=RickyTall;150028]\n'how much of this could be automated?'\n[/quote]</p>\n\n<p>I work for a company that tries to automate most of these steps :-D</p>",
          "rawMarkdown": "[quote=RickyTall;150028]\r\n'how much of this could be automated?'\r\n[/quote]\r\n\r\nI work for a company that tries to automate most of these steps :-D",
          "votes": 3
        }
      ]
    },
    {
      "id": 149850,
      "postDate": "2016-12-13T02:28:38.400Z",
      "content": "<p>What does step6 mean? And how many stacked predictions you got for ensemble? Thanks.</p>",
      "rawMarkdown": "What does step6 mean? And how many stacked predictions you got for ensemble? Thanks.",
      "replies": [
        {
          "id": 149853,
          "postDate": "2016-12-13T02:32:49.190Z",
          "content": "<p>[quote=Yizhi Tao;149850]</p>\n\n<p>What does step6 mean? And how many stacked predictions you got for ensemble? Thanks.</p>\n\n<p>[/quote]</p>\n\n<p>I did PCA on the stacked predicitons, and then added the first principle component to the stacked predictions before optimizing.  I had 59 models in my final blend + the first PC component of those models.</p>",
          "rawMarkdown": "[quote=Yizhi Tao;149850]\r\n\r\nWhat does step6 mean? And how many stacked predictions you got for ensemble? Thanks.\r\n\r\n[/quote]\r\n\r\nI did PCA on the stacked predicitons, and then added the first principle component to the stacked predictions before optimizing.  I had 59 models in my final blend + the first PC component of those models.",
          "votes": 1
        }
      ]
    },
    {
      "id": 149847,
      "postDate": "2016-12-13T02:04:51.620Z",
      "content": "<p>Could you explain what's PC1?</p>",
      "rawMarkdown": "Could you explain what's PC1?",
      "replies": [
        {
          "id": 149848,
          "postDate": "2016-12-13T02:05:44.247Z",
          "content": "<p>[quote=modkzs;149847]</p>\n\n<p>Could you explain what's PC1?</p>\n\n<p>[/quote]\nFirst principal component?</p>",
          "rawMarkdown": "[quote=modkzs;149847]\r\n\r\nCould you explain what's PC1?\r\n\r\n[/quote]\r\nFirst principal component?",
          "votes": 1
        }
      ]
    }
  ],
  "complete": true,
  "source": "live",
  "fetched_at": "2026-10-19T17:15:26Z",
  "competition_id": 5325,
  "competition_slug": "allstate-claims-severity",
  "team_id": 384857,
  "solution_url": "/competitions/allstate-claims-severity/writeups/zach-my-approach"
}