{
  "id": 3559,
  "title": "Ben: Code to create test set from training",
  "url": "/competitions/flight/discussion/3559",
  "author_name": "",
  "post_date": "2013-01-09T06:54:33.217Z",
  "votes": null,
  "comment_count": 2,
  "views": 2694,
  "content": "<p>Hi Ben,</p>\r\n<p>You were to post a mechanism to get test set from training. THere is no need for code from you - just tell us the logic that you use.</p>\r\n<p>For example, here is my R Code to create test from training:</p>\r\n<p>Here is what I am doing - &nbsp;however I see that the CV score for the most recent value of ERA/EGA also differs from public leaderboard score. This means that there is some additional logic to code below</p>\r\n<p>&nbsp;</p>\r\n<p>My Method:</p>\r\n<p>1. remove flights that do not arrive/depart in US</p>\r\n<p>2.&nbsp;remove flights that have an invalid form of datetime - either arrival or departure date</p>\r\n<p>3.&nbsp;only flights that are in air at that time</p>\r\n<p>4.&nbsp;remove flights whose gate_departure time is after runway_departure_time OR whose gate arrival is before runway arrival</p>\r\n<p>5. use the same cutoff days as in the file</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>What else is needed to be done?</p>\r\n<p>Thanks<br>\r\nkiran&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<pre>cutoff_days &lt;- read.csv (paste (cv_path, 'days.csv', sep='/'), header=TRUE, stringsAsFactors = FALSE)<br>\tcutoff_days$cutoff_time &lt;-  as.POSIXct (cutoff_days$selected_cutoff_time, tz=&quot;UTC&quot;, format = &quot;%Y-%m-%d %H:%M:%S&quot;, origin=&quot;1970-1-1&quot;  )<br><br>\t#myNms &lt;- c (&quot;flight_history_id&quot;, &quot;departure_airport_code&quot;, &quot;arrival_airport_code&quot;, \t&quot;published_departure&quot;,\t&quot;published_arrival&quot;,\t&quot;scheduled_gate_departure&quot;,\t&quot;scheduled_gate_arrival&quot;,\t&quot;scheduled_runway_departure&quot;,   &quot;scheduled_runway_arrival&quot;, &quot;actual_gate_arrival&quot;, &quot;actual_runway_arrival&quot;, &quot;actual_gate_arrival_mins&quot;, &quot;actual_runway_arrival_mins&quot;, &quot;airline_icao_code&quot;,&quot;departure_airport_icao_code&quot;, &quot;arrival_airport_icao_code&quot;, &quot;creator_code&quot;, &quot;scheduled_aircraft_type&quot;, &quot;actual_aircraft_type&quot;, &quot;scheduled_air_time&quot;, &quot;actual_gate_departure&quot;, &quot;actual_runway_departure&quot;)<br><br>\tmyNms &lt;- c (&quot;flight_history_id&quot;,          &quot;departure_airport_code&quot;   ,  &quot;arrival_airport_code&quot;,       &quot;published_departure&quot;       , &quot;published_arrival&quot;,          &quot;scheduled_gate_departure&quot;  , &quot;scheduled_gate_arrival&quot;,     &quot;scheduled_runway_departure&quot;,<br> &quot;scheduled_runway_arrival&quot;)<br><br>\tfor (myDate in test_dates) {<br>\t\tprint (paste (&quot;for myDate&quot;, myDate, sep=&quot;:&quot;))<br><br>\t\tbase_day_path &lt;- paste (cv_path,myDate, sep=&quot;/&quot;)<br>\t\tmyList &lt;- summarize_flight_history_day (base_day_path, test_day_path = NA)<br>\t\tflighthistory &lt;- myList [[1]]<br><br>\t\t# remove flights that do not arrive and depart both in the US<br>\t\tflighthistory_departs_from_us &lt;- flighthistory$departure_airport_icao_code %in% us_icao_codes$icao_code<br>\t\tflighthistory_arrives_in_us &lt;- flighthistory$arrival_airport_icao_code %in% us_icao_codes$icao_code<br>\t\tmyRows &lt;- which ((which(flighthistory_arrives_in_us == TRUE) &amp; which(flighthistory_departs_from_us == TRUE)) == TRUE)<br>\t\tflighthistory &lt;- flighthistory[myRows,]<br><br>\t\t# remove flights that have an invalid form of datetime - either arrival or departure date<br>\t\tignoreRows &lt;- c(which (is.na (flighthistory$actual_gate_departure) == TRUE)<br>\t\t, which (is.na (flighthistory$actual_gate_arrival) == TRUE)<br>\t\t, which (is.na (flighthistory$actual_runway_arrival) == TRUE)<br>\t\t, which (is.na (flighthistory$actual_runway_departure) == TRUE))<br>\t\tignoreRows &lt;- unique (ignoreRows)<br><br>\t\tflighthistory &lt;- flighthistory [-ignoreRows,]<br><br>\t\t# only flights that are in air at that time<br>\t\tflighthistory &lt;- flighthistory [!is.na(flighthistory$actual_gate_arrival),]<br>\t\tflighthistory &lt;- flighthistory [!is.na(flighthistory$actual_runway_arrival),]<br><br><br>\t\t# remove flights whose gate_departure time is after runway_departure_time OR whose gate arrival is before runway arrival<br>\t\tignoreRows &lt;- c(which (flighthistory$actual_gate_departure &gt; flighthistory$actual_runway_departure), which (flighthistory$actual_runway_arrival &gt; flighthistory$actual_gate_arrival))<br>\t\tignoreRows &lt;- unique (ignoreRows)<br><br>\t\tflighthistory &lt;- flighthistory [-ignoreRows,]<br><br>\t\t<br><br>\t\tflighthistory$cutoff_time &lt;- as.POSIXct (cutoff_days [cutoff_days$folder_name == myDate, &quot;selected_cutoff_time&quot;],  tz=&quot;UTC&quot;, format = &quot;%Y-%m-%d %H:%M:%S&quot;, origin=&quot;1970-1-1&quot;  )<br>\t\t<br>\t\ttestflighthistory &lt;- flighthistory [flighthistory$actual_gate_arrival &gt;= flighthistory$cutoff_time,]<br><br> \t\t<br>\t\t<br>\t\twrite.csv (x=testflighthistory[,myNms]  ,file=paste (cv_path, myDate, &quot;test_flights_new.csv&quot;, sep= &quot;/&quot;), row.names = FALSE)<br><br><br>\t}</pre>",
  "messages": [
    {
      "id": "19121",
      "postDate": "01/09/2013 06:54:33",
      "content": "<p>Hi Ben,</p>\r\n<p>You were to post a mechanism to get test set from training. THere is no need for code from you - just tell us the logic that you use.</p>\r\n<p>For example, here is my R Code to create test from training:</p>\r\n<p>Here is what I am doing - &nbsp;however I see that the CV score for the most recent value of ERA/EGA also differs from public leaderboard score. This means that there is some additional logic to code below</p>\r\n<p>&nbsp;</p>\r\n<p>My Method:</p>\r\n<p>1. remove flights that do not arrive/depart in US</p>\r\n<p>2.&nbsp;remove flights that have an invalid form of datetime - either arrival or departure date</p>\r\n<p>3.&nbsp;only flights that are in air at that time</p>\r\n<p>4.&nbsp;remove flights whose gate_departure time is after runway_departure_time OR whose gate arrival is before runway arrival</p>\r\n<p>5. use the same cutoff days as in the file</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>What else is needed to be done?</p>\r\n<p>Thanks<br>\r\nkiran&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<pre>cutoff_days &lt;- read.csv (paste (cv_path, 'days.csv', sep='/'), header=TRUE, stringsAsFactors = FALSE)<br>\tcutoff_days$cutoff_time &lt;-  as.POSIXct (cutoff_days$selected_cutoff_time, tz=&quot;UTC&quot;, format = &quot;%Y-%m-%d %H:%M:%S&quot;, origin=&quot;1970-1-1&quot;  )<br><br>\t#myNms &lt;- c (&quot;flight_history_id&quot;, &quot;departure_airport_code&quot;, &quot;arrival_airport_code&quot;, \t&quot;published_departure&quot;,\t&quot;published_arrival&quot;,\t&quot;scheduled_gate_departure&quot;,\t&quot;scheduled_gate_arrival&quot;,\t&quot;scheduled_runway_departure&quot;,   &quot;scheduled_runway_arrival&quot;, &quot;actual_gate_arrival&quot;, &quot;actual_runway_arrival&quot;, &quot;actual_gate_arrival_mins&quot;, &quot;actual_runway_arrival_mins&quot;, &quot;airline_icao_code&quot;,&quot;departure_airport_icao_code&quot;, &quot;arrival_airport_icao_code&quot;, &quot;creator_code&quot;, &quot;scheduled_aircraft_type&quot;, &quot;actual_aircraft_type&quot;, &quot;scheduled_air_time&quot;, &quot;actual_gate_departure&quot;, &quot;actual_runway_departure&quot;)<br><br>\tmyNms &lt;- c (&quot;flight_history_id&quot;,          &quot;departure_airport_code&quot;   ,  &quot;arrival_airport_code&quot;,       &quot;published_departure&quot;       , &quot;published_arrival&quot;,          &quot;scheduled_gate_departure&quot;  , &quot;scheduled_gate_arrival&quot;,     &quot;scheduled_runway_departure&quot;,<br> &quot;scheduled_runway_arrival&quot;)<br><br>\tfor (myDate in test_dates) {<br>\t\tprint (paste (&quot;for myDate&quot;, myDate, sep=&quot;:&quot;))<br><br>\t\tbase_day_path &lt;- paste (cv_path,myDate, sep=&quot;/&quot;)<br>\t\tmyList &lt;- summarize_flight_history_day (base_day_path, test_day_path = NA)<br>\t\tflighthistory &lt;- myList [[1]]<br><br>\t\t# remove flights that do not arrive and depart both in the US<br>\t\tflighthistory_departs_from_us &lt;- flighthistory$departure_airport_icao_code %in% us_icao_codes$icao_code<br>\t\tflighthistory_arrives_in_us &lt;- flighthistory$arrival_airport_icao_code %in% us_icao_codes$icao_code<br>\t\tmyRows &lt;- which ((which(flighthistory_arrives_in_us == TRUE) &amp; which(flighthistory_departs_from_us == TRUE)) == TRUE)<br>\t\tflighthistory &lt;- flighthistory[myRows,]<br><br>\t\t# remove flights that have an invalid form of datetime - either arrival or departure date<br>\t\tignoreRows &lt;- c(which (is.na (flighthistory$actual_gate_departure) == TRUE)<br>\t\t, which (is.na (flighthistory$actual_gate_arrival) == TRUE)<br>\t\t, which (is.na (flighthistory$actual_runway_arrival) == TRUE)<br>\t\t, which (is.na (flighthistory$actual_runway_departure) == TRUE))<br>\t\tignoreRows &lt;- unique (ignoreRows)<br><br>\t\tflighthistory &lt;- flighthistory [-ignoreRows,]<br><br>\t\t# only flights that are in air at that time<br>\t\tflighthistory &lt;- flighthistory [!is.na(flighthistory$actual_gate_arrival),]<br>\t\tflighthistory &lt;- flighthistory [!is.na(flighthistory$actual_runway_arrival),]<br><br><br>\t\t# remove flights whose gate_departure time is after runway_departure_time OR whose gate arrival is before runway arrival<br>\t\tignoreRows &lt;- c(which (flighthistory$actual_gate_departure &gt; flighthistory$actual_runway_departure), which (flighthistory$actual_runway_arrival &gt; flighthistory$actual_gate_arrival))<br>\t\tignoreRows &lt;- unique (ignoreRows)<br><br>\t\tflighthistory &lt;- flighthistory [-ignoreRows,]<br><br>\t\t<br><br>\t\tflighthistory$cutoff_time &lt;- as.POSIXct (cutoff_days [cutoff_days$folder_name == myDate, &quot;selected_cutoff_time&quot;],  tz=&quot;UTC&quot;, format = &quot;%Y-%m-%d %H:%M:%S&quot;, origin=&quot;1970-1-1&quot;  )<br>\t\t<br>\t\ttestflighthistory &lt;- flighthistory [flighthistory$actual_gate_arrival &gt;= flighthistory$cutoff_time,]<br><br> \t\t<br>\t\t<br>\t\twrite.csv (x=testflighthistory[,myNms]  ,file=paste (cv_path, myDate, &quot;test_flights_new.csv&quot;, sep= &quot;/&quot;), row.names = FALSE)<br><br><br>\t}</pre>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "19139",
      "postDate": "01/09/2013 19:02:22",
      "content": "<p>is there a chance of ben responding?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "19733",
      "postDate": "01/27/2013 02:39:05",
      "content": "<p>Hi Kiran</p>\r\n<p>can you clarify where you got days.csv and what its contents are.</p>\r\n<p>what are the test_dates.</p>\r\n<p>I really appreciate your help</p>\r\n<p>Thanks</p>\r\n<p>&nbsp;</p>\r\n<pre class=\"x_prettyprint\">cutoff_days &lt;- read.csv (paste (cv_path, 'days.csv', sep='/'), header=TRUE, stringsAsFactors = FALSE)<br>\tcutoff_days$cutoff_time &lt;-  as.POSIXct (cutoff_days$selected_cutoff_time, tz=&quot;UTC&quot;, format = &quot;%Y-%m-%d %H:%M:%S&quot;, origin=&quot;1970-1-1&quot;  )<br><br>\tfor (myDate in test_dates) {<br>\t\tprint (paste (&quot;for myDate&quot;, myDate, sep=&quot;:&quot;))<br><br></pre>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 19139,
      "author_name": "rkirana",
      "author_url": "",
      "post_date": "01/09/2013 19:02:22",
      "content": "<p>is there a chance of ben responding?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 19733,
      "author_name": "drivetheresult",
      "author_url": "",
      "post_date": "01/27/2013 02:39:05",
      "content": "<p>Hi Kiran</p>\r\n<p>can you clarify where you got days.csv and what its contents are.</p>\r\n<p>what are the test_dates.</p>\r\n<p>I really appreciate your help</p>\r\n<p>Thanks</p>\r\n<p>&nbsp;</p>\r\n<pre class=\"x_prettyprint\">cutoff_days &lt;- read.csv (paste (cv_path, 'days.csv', sep='/'), header=TRUE, stringsAsFactors = FALSE)<br>\tcutoff_days$cutoff_time &lt;-  as.POSIXct (cutoff_days$selected_cutoff_time, tz=&quot;UTC&quot;, format = &quot;%Y-%m-%d %H:%M:%S&quot;, origin=&quot;1970-1-1&quot;  )<br><br>\tfor (myDate in test_dates) {<br>\t\tprint (paste (&quot;for myDate&quot;, myDate, sep=&quot;:&quot;))<br><br></pre>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "19121": "",
    "19139": "",
    "19733": ""
  },
  "source": "meta"
}