{
  "id": 38105,
  "title": "SQL feature engineering + XGBoost (.4026 private LB, 1/2 of #100 solution)",
  "content": "<p><a href=\"https://github.com/happycube/kaggle2017/tree/master/instacart\">https://github.com/happycube/kaggle2017/tree/master/instacart</a> </p>\n\n<p>This isn't much compared to sjv's #3 code post*, but I'll share what I've got anyway :)  It's a pretty basic model using features I generated largely based on Sh1ng's kernel, with some new features that handle departments like they were products (marginally useful) - the new thing is the use of SQL queries etc to run the feature engineering.</p>\n\n<p>I started with SQLite but needed arrays and aggregate functions, which led me to set up Postgres for the first time.  I'm completely new at it, so it's not as idiomatic and elegant as it could be, but I'm still pretty proud of it as a first project, and it fills in a hole in my knowledge a bit.</p>\n\n<p>Hope you find something useful here, especially for those reading this after the next competition with relational data comes up :)</p>\n\n<p>(* - I wasn't expecting a medal at all, being #277 on the public LB - but I was still planning to post anyway!)</p>",
  "comments": [
    {
      "id": 213800,
      "author_name": "Aljaž",
      "author_url": "",
      "post_date": "2017-08-15T09:15:32.527000",
      "content": "<p>Thanks for sharing and congrats! It'll be nice to have something familiar to practice SQL with :-)</p>",
      "votes": 3,
      "replies": []
    },
    {
      "id": 213621,
      "author_name": "Serigne ",
      "author_url": "",
      "post_date": "2017-08-15T02:03:00.700000",
      "content": "<p>Thanks happycube for sharing</p>\n\n<p>And congrats for your brillant idea (particularly being new at it ) </p>\n\n<p>And yes it may be useful for next competitions </p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 213739,
      "author_name": "A_b",
      "author_url": "",
      "post_date": "2017-08-15T06:30:39.427000",
      "content": "<p>Interesting approach, good job! Was it easier for you to use SQL compared to python for feature engineering in such a competition? - Cheers</p>",
      "votes": 2,
      "replies": [
        {
          "id": 213947,
          "author_name": "happycube",
          "author_url": "",
          "post_date": "2017-08-15T15:01:56.827000",
          "content": "<p>Once I'm fully seasoned, I think it would be.  Near the end I was able to make new feature groups relatively quickly (the department-as-product stuff at the end)</p>\n\n<p>The enforced separation of concerns is nice to have in any case.</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 213734,
      "author_name": "Fred Navruzov",
      "author_url": "",
      "post_date": "2017-08-15T06:24:00.857000",
      "content": "<p>Thank you, very nice, \"good old SQL\" never gets too old :)</p>",
      "votes": 2,
      "replies": []
    }
  ],
  "comment_count": 5,
  "messages": [
    {
      "id": 213612,
      "postDate": "2017-08-15T01:55:36.993Z",
      "content": "<p><a href=\"https://github.com/happycube/kaggle2017/tree/master/instacart\">https://github.com/happycube/kaggle2017/tree/master/instacart</a> </p>\n\n<p>This isn't much compared to sjv's #3 code post*, but I'll share what I've got anyway :)  It's a pretty basic model using features I generated largely based on Sh1ng's kernel, with some new features that handle departments like they were products (marginally useful) - the new thing is the use of SQL queries etc to run the feature engineering.</p>\n\n<p>I started with SQLite but needed arrays and aggregate functions, which led me to set up Postgres for the first time.  I'm completely new at it, so it's not as idiomatic and elegant as it could be, but I'm still pretty proud of it as a first project, and it fills in a hole in my knowledge a bit.</p>\n\n<p>Hope you find something useful here, especially for those reading this after the next competition with relational data comes up :)</p>\n\n<p>(* - I wasn't expecting a medal at all, being #277 on the public LB - but I was still planning to post anyway!)</p>",
      "rawMarkdown": "https://github.com/happycube/kaggle2017/tree/master/instacart \n\nThis isn't much compared to sjv's #3 code post*, but I'll share what I've got anyway :)  It's a pretty basic model using features I generated largely based on Sh1ng's kernel, with some new features that handle departments like they were products (marginally useful) - the new thing is the use of SQL queries etc to run the feature engineering.\n\nI started with SQLite but needed arrays and aggregate functions, which led me to set up Postgres for the first time.  I'm completely new at it, so it's not as idiomatic and elegant as it could be, but I'm still pretty proud of it as a first project, and it fills in a hole in my knowledge a bit.\n\nHope you find something useful here, especially for those reading this after the next competition with relational data comes up :)\n\n(* - I wasn't expecting a medal at all, being #277 on the public LB - but I was still planning to post anyway!)",
      "votes": 21
    },
    {
      "id": 213800,
      "postDate": "2017-08-15T09:15:32.527Z",
      "content": "<p>Thanks for sharing and congrats! It'll be nice to have something familiar to practice SQL with :-)</p>",
      "rawMarkdown": "Thanks for sharing and congrats! It'll be nice to have something familiar to practice SQL with :-)",
      "votes": 3
    },
    {
      "id": 213621,
      "postDate": "2017-08-15T02:03:00.700Z",
      "content": "<p>Thanks happycube for sharing</p>\n\n<p>And congrats for your brillant idea (particularly being new at it ) </p>\n\n<p>And yes it may be useful for next competitions </p>",
      "rawMarkdown": "Thanks happycube for sharing\n\nAnd congrats for your brillant idea (particularly being new at it ) \n\nAnd yes it may be useful for next competitions ",
      "votes": 1
    },
    {
      "id": 213739,
      "postDate": "2017-08-15T06:30:39.427Z",
      "content": "<p>Interesting approach, good job! Was it easier for you to use SQL compared to python for feature engineering in such a competition? - Cheers</p>",
      "rawMarkdown": "Interesting approach, good job! Was it easier for you to use SQL compared to python for feature engineering in such a competition? - Cheers",
      "votes": 2,
      "replies": [
        {
          "id": 213947,
          "postDate": "2017-08-15T15:01:56.827Z",
          "content": "<p>Once I'm fully seasoned, I think it would be.  Near the end I was able to make new feature groups relatively quickly (the department-as-product stuff at the end)</p>\n\n<p>The enforced separation of concerns is nice to have in any case.</p>",
          "rawMarkdown": "Once I'm fully seasoned, I think it would be.  Near the end I was able to make new feature groups relatively quickly (the department-as-product stuff at the end)\n\nThe enforced separation of concerns is nice to have in any case.",
          "votes": 1
        }
      ]
    },
    {
      "id": 213734,
      "postDate": "2017-08-15T06:24:00.857Z",
      "content": "<p>Thank you, very nice, \"good old SQL\" never gets too old :)</p>",
      "rawMarkdown": "Thank you, very nice, \"good old SQL\" never gets too old :)",
      "votes": 2
    }
  ],
  "complete": true,
  "source": "live",
  "fetched_at": "2026-10-20T02:01:22Z",
  "competition_id": 6644,
  "competition_slug": "basket-analysis",
  "team_id": 719231,
  "solution_url": "/competitions/basket-analysis/writeups/happycube-sql-feature-engineering-xgboost-4026-pri"
}