{
  "id": 5276,
  "title": "Newbies support",
  "url": "/competitions/accelerometer-biometric-competition/discussion/5276",
  "author_name": "",
  "post_date": "2013-08-02T15:38:49.060Z",
  "votes": 18,
  "comment_count": 18,
  "views": 9489,
  "content": "<p>In previous competitions it was started a good tradition to share basic code with newbies. Here is the very simple solution based on averaging data for device and sequence and their further comparison.&nbsp;</p>\n<p>The description of the algorithm:</p>\n<p>- &nbsp;count mean of data from training data for devices</p>\n<p>- count mean of data from testing data for sequences</p>\n<p>- calculate distance matrix between them</p>\n<p>- sort distances in descending order in the rows</p>\n<p>- position of the hypothesis from the question file in a row&nbsp;for the given sequence is our score</p>\n<p>Mean calculation is not optimized so I included also 'percent done' script downloaded from the web to control the execution flow.</p>\n<p>To run the scripts download them to the same folder and add there data files.</p>\n<p>Run main.m to get the submission.csv file.</p>\n<p>Hope I'll have enough time to compete in this contest and will share some of my further improvements.</p>\n<p>&nbsp;P.S. This code will give&nbsp;0.69577 leaderboard score.</p>\n<p>P. P. S. main_updated added, that's the right version of the submission generating procedure. It's result should be&nbsp;0.65791</p>",
  "messages": [
    {
      "id": "28069",
      "postDate": "08/02/2013 15:38:49",
      "content": "<p>In previous competitions it was started a good tradition to share basic code with newbies. Here is the very simple solution based on averaging data for device and sequence and their further comparison.&nbsp;</p>\n<p>The description of the algorithm:</p>\n<p>- &nbsp;count mean of data from training data for devices</p>\n<p>- count mean of data from testing data for sequences</p>\n<p>- calculate distance matrix between them</p>\n<p>- sort distances in descending order in the rows</p>\n<p>- position of the hypothesis from the question file in a row&nbsp;for the given sequence is our score</p>\n<p>Mean calculation is not optimized so I included also 'percent done' script downloaded from the web to control the execution flow.</p>\n<p>To run the scripts download them to the same folder and add there data files.</p>\n<p>Run main.m to get the submission.csv file.</p>\n<p>Hope I'll have enough time to compete in this contest and will share some of my further improvements.</p>\n<p>&nbsp;P.S. This code will give&nbsp;0.69577 leaderboard score.</p>\n<p>P. P. S. main_updated added, that's the right version of the submission generating procedure. It's result should be&nbsp;0.65791</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "28076",
      "postDate": "08/02/2013 17:11:15",
      "content": "<p>Interesting. This is very similar to my submission (I'm right behind you at the moment). The only difference is I didn't sort the distances. My final score was just the inverse distance from the test sequence to the training device. I'll upload R and may be python (just learning) code later</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "28097",
      "postDate": "08/02/2013 23:24:12",
      "content": "<p>I see, inverse distance was my former version I suppose... But since we need relative order, it's better use the position with respect to the other estimations.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "28112",
      "postDate": "08/03/2013 06:51:31",
      "content": "<p>[quote=jlburkhead;28076]</p>\n<p>Interesting. This is very similar to my submission (I'm right behind you at the moment). The only difference is I didn't sort the distances. My final score was just the inverse distance from the test sequence to the training device. I'll upload R and may be python (just learning) code later</p>\n<p>[/quote]</p>\n<p>Well, if I do everything right, I get the same result as you :). I did it wrong when took 1st to 3rd column to count average (so I included time and excluded Z component) and got better result (should have taken 2nd to 4th instead). This is a cheat indeed :). Will change the main.m code now.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "28175",
      "postDate": "08/04/2013 12:31:08",
      "content": "<p>Thanks a lot!</p>\n<p>&nbsp;</p>\n<p>Regards</p>\n<p>Jay</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "28176",
      "postDate": "08/04/2013 13:20:02",
      "content": "<p>R code for both the k-NN benchmark and my latest submission which calculates the mean X, Y and Z then sorts the distance from the test point to the training devices. Available here&nbsp;https://github.com/jlburkhead/abc</p>\n<p>&nbsp;</p>\n<p>edit: I should add that this won't work as is on windows (multicore isn't available for windows). You can just change mclapply to lapply although it will take longer to run. This took ~1 hour to run on a 2 core ec2 instance</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "28189",
      "postDate": "08/05/2013 00:56:44",
      "content": "As a side note, here's the multi processing method I use on a single windows machine using Snow. It'll will do much the same as multicore (and can even be also used to cluster different machines as well). The example uses 2 cores, adding more is adding the hostname(s) in line the makeCluser() and increasing the numbers in cluserApply(). I also don't think mclapply will work with a Snow cluster, but your code can probably be adjusted accordingly. <p>\n\nParaPred &lt;- function () { library(doSNOW)<br>\n                         cl &lt;- makeCluster(c(&quot;localhost&quot;, &quot;localhost&quot;), type = &quot;SOCK&quot;, outfile=&quot;snow.log&quot;)<br>\n                         clusterApply(cl, 1:2, get(&quot;+&quot;), 2)<br>\n                         registerDoSNOW(cl)<br>\n                         getDoParWorkers()}\n</p><p>\n\n(I'm needing it - my current model will take about 3 days on 3 CPU's)</p>\n\nedit: for markups.",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "28344",
      "postDate": "08/07/2013 07:07:12",
      "content": "<p>I'm using multivariate normals (with x,y,z by device but not timestamp) and after I calculate likelihood in sequences for quizdevice and sort the outcome but I guess this way is not the way. Thanks for the code.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "28381",
      "postDate": "08/07/2013 16:37:57",
      "content": "<p>Very novice question... importing the csv in to Matlab is proving cumbersome, did you bring the data in by some other means?</p>\n<p>&nbsp;</p>\n<p>Cheers</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "28383",
      "postDate": "08/07/2013 16:55:55",
      "content": "<p>[quote=Alec Jeffery;28381]</p>\n<p>Very novice question... importing the csv in to Matlab is proving cumbersome, did you bring the data in by some other means?</p>\n<p>&nbsp;</p>\n<p>Cheers</p>\n<p>[/quote]</p>\n<p>It doesn't seem to be hard in matlab:</p>\n<p>train_dt = csvread('train.csv',1,0);</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "28404",
      "postDate": "08/07/2013 23:43:32",
      "content": "<p>Does anyone has python version to share?</p>\n<p>Thanks.</p>\n<p>&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "28533",
      "postDate": "08/10/2013 21:09:24",
      "content": "<p>I am working in Python/ScikitLearn and&nbsp;I intend to share a initial code soon (like the adveboy&nbsp;solution).&nbsp;A good try can be use the sampling rate of the device as a feature.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "28536",
      "postDate": "08/10/2013 23:59:38",
      "content": "<p>that I'm aware of, there's no trimmed mean function in numpy so you've got to write it yourself!</p>\n<p><code>import numpy as np</code></p>\n<p><code>## Trimmed\\Truncated Mean<br>## trim takes values between 0 and 100 for the relative percentile<br>def trim_mean(x, trim=10):<br></code><code>&nbsp; &nbsp; lower_bound = np.percentile(x, trim)<br></code><code>&nbsp; &nbsp; upper_bound = np.percentile(x, (100-trim))<br></code><code>&nbsp; &nbsp; return np.mean(x[(x&gt;=lower_bound) &amp; (x&lt;=upper_bound)])</code></p>\n<p>Or copy the above!&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29613",
      "postDate": "08/28/2013 01:28:22",
      "content": "<p>Here is some python code to load the train file using the pandas library:</p>\n<p>&nbsp;</p>\n<p>import pandas as pd</p>\n<p>df = pd.read_csv('train.csv')</p>\n<p>df.sort(columns=['Device','T'])&nbsp;&nbsp; #&nbsp; just in case it is not sorted</p>\n<p>devices = df['Device'].unique()</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29620",
      "postDate": "08/28/2013 04:19:14",
      "content": "<p>I get a MemoryError in python when I call read_csv.('train.csv'), although it seems to work for others. I've gotten around it by loading the data into a sqlite database and only loading smaller pieces of the data. My laptop has 8GB of ram so I'm not really sure why python blows up.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29622",
      "postDate": "08/28/2013 04:25:12",
      "content": "<p>Is your Python compiled for 64 bits? If not, the 32 bit is not enough to read that file!</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "29623",
      "postDate": "08/28/2013 04:37:46",
      "content": "<p>You're right, thanks for the reminder. I installed the 32-bit version of Python(x,y) because of I used to have compatibility issues between 64-bit and Eclipse/PyDev. Not sure if the issues still exist, maybe I'll look into Spyder..</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "31050",
      "postDate": "09/17/2013 15:14:09",
      "content": "<p>I'm not an expert but I guess it could be a problem of the python version. I was helping a friend of mine which had the same problem on a 4GB laptop and with a brand new python installation (anaconda) everything worked well.</p>\n<p>&nbsp;</p>\n<p>&nbsp;</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "33335",
      "postDate": "11/06/2013 21:30:01",
      "content": "",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 28076,
      "author_name": "foobarbazquux",
      "author_url": "",
      "post_date": "08/02/2013 17:11:15",
      "content": "<p>Interesting. This is very similar to my submission (I'm right behind you at the moment). The only difference is I didn't sort the distances. My final score was just the inverse distance from the test sequence to the training device. I'll upload R and may be python (just learning) code later</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 28097,
      "author_name": "",
      "author_url": "",
      "post_date": "08/02/2013 23:24:12",
      "content": "<p>I see, inverse distance was my former version I suppose... But since we need relative order, it's better use the position with respect to the other estimations.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 28112,
      "author_name": "",
      "author_url": "",
      "post_date": "08/03/2013 06:51:31",
      "content": "<p>[quote=jlburkhead;28076]</p>\n<p>Interesting. This is very similar to my submission (I'm right behind you at the moment). The only difference is I didn't sort the distances. My final score was just the inverse distance from the test sequence to the training device. I'll upload R and may be python (just learning) code later</p>\n<p>[/quote]</p>\n<p>Well, if I do everything right, I get the same result as you :). I did it wrong when took 1st to 3rd column to count average (so I included time and excluded Z component) and got better result (should have taken 2nd to 4th instead). This is a cheat indeed :). Will change the main.m code now.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 28175,
      "author_name": "jayadevmateti",
      "author_url": "",
      "post_date": "08/04/2013 12:31:08",
      "content": "<p>Thanks a lot!</p>\n<p>&nbsp;</p>\n<p>Regards</p>\n<p>Jay</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 28176,
      "author_name": "foobarbazquux",
      "author_url": "",
      "post_date": "08/04/2013 13:20:02",
      "content": "<p>R code for both the k-NN benchmark and my latest submission which calculates the mean X, Y and Z then sorts the distance from the test point to the training devices. Available here&nbsp;https://github.com/jlburkhead/abc</p>\n<p>&nbsp;</p>\n<p>edit: I should add that this won't work as is on windows (multicore isn't available for windows). You can just change mclapply to lapply although it will take longer to run. This took ~1 hour to run on a 2 core ec2 instance</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 28189,
      "author_name": "majhra",
      "author_url": "",
      "post_date": "08/05/2013 00:56:44",
      "content": "As a side note, here's the multi processing method I use on a single windows machine using Snow. It'll will do much the same as multicore (and can even be also used to cluster different machines as well). The example uses 2 cores, adding more is adding the hostname(s) in line the makeCluser() and increasing the numbers in cluserApply(). I also don't think mclapply will work with a Snow cluster, but your code can probably be adjusted accordingly. <p>\n\nParaPred &lt;- function () { library(doSNOW)<br>\n                         cl &lt;- makeCluster(c(&quot;localhost&quot;, &quot;localhost&quot;), type = &quot;SOCK&quot;, outfile=&quot;snow.log&quot;)<br>\n                         clusterApply(cl, 1:2, get(&quot;+&quot;), 2)<br>\n                         registerDoSNOW(cl)<br>\n                         getDoParWorkers()}\n</p><p>\n\n(I'm needing it - my current model will take about 3 days on 3 CPU's)</p>\n\nedit: for markups.",
      "votes": null,
      "replies": []
    },
    {
      "id": 28344,
      "author_name": "jbm1966",
      "author_url": "",
      "post_date": "08/07/2013 07:07:12",
      "content": "<p>I'm using multivariate normals (with x,y,z by device but not timestamp) and after I calculate likelihood in sequences for quizdevice and sort the outcome but I guess this way is not the way. Thanks for the code.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 28381,
      "author_name": "beastorchestra",
      "author_url": "",
      "post_date": "08/07/2013 16:37:57",
      "content": "<p>Very novice question... importing the csv in to Matlab is proving cumbersome, did you bring the data in by some other means?</p>\n<p>&nbsp;</p>\n<p>Cheers</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 28383,
      "author_name": "",
      "author_url": "",
      "post_date": "08/07/2013 16:55:55",
      "content": "<p>[quote=Alec Jeffery;28381]</p>\n<p>Very novice question... importing the csv in to Matlab is proving cumbersome, did you bring the data in by some other means?</p>\n<p>&nbsp;</p>\n<p>Cheers</p>\n<p>[/quote]</p>\n<p>It doesn't seem to be hard in matlab:</p>\n<p>train_dt = csvread('train.csv',1,0);</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 28404,
      "author_name": "kevinhwang",
      "author_url": "",
      "post_date": "08/07/2013 23:43:32",
      "content": "<p>Does anyone has python version to share?</p>\n<p>Thanks.</p>\n<p>&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 28533,
      "author_name": "ericcouto",
      "author_url": "",
      "post_date": "08/10/2013 21:09:24",
      "content": "<p>I am working in Python/ScikitLearn and&nbsp;I intend to share a initial code soon (like the adveboy&nbsp;solution).&nbsp;A good try can be use the sampling rate of the device as a feature.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 28536,
      "author_name": "alzmcr",
      "author_url": "",
      "post_date": "08/10/2013 23:59:38",
      "content": "<p>that I'm aware of, there's no trimmed mean function in numpy so you've got to write it yourself!</p>\n<p><code>import numpy as np</code></p>\n<p><code>## Trimmed\\Truncated Mean<br>## trim takes values between 0 and 100 for the relative percentile<br>def trim_mean(x, trim=10):<br></code><code>&nbsp; &nbsp; lower_bound = np.percentile(x, trim)<br></code><code>&nbsp; &nbsp; upper_bound = np.percentile(x, (100-trim))<br></code><code>&nbsp; &nbsp; return np.mean(x[(x&gt;=lower_bound) &amp; (x&lt;=upper_bound)])</code></p>\n<p>Or copy the above!&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 29613,
      "author_name": "geringer",
      "author_url": "",
      "post_date": "08/28/2013 01:28:22",
      "content": "<p>Here is some python code to load the train file using the pandas library:</p>\n<p>&nbsp;</p>\n<p>import pandas as pd</p>\n<p>df = pd.read_csv('train.csv')</p>\n<p>df.sort(columns=['Device','T'])&nbsp;&nbsp; #&nbsp; just in case it is not sorted</p>\n<p>devices = df['Device'].unique()</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 29620,
      "author_name": "mjyhan",
      "author_url": "",
      "post_date": "08/28/2013 04:19:14",
      "content": "<p>I get a MemoryError in python when I call read_csv.('train.csv'), although it seems to work for others. I've gotten around it by loading the data into a sqlite database and only loading smaller pieces of the data. My laptop has 8GB of ram so I'm not really sure why python blows up.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 29622,
      "author_name": "alzmcr",
      "author_url": "",
      "post_date": "08/28/2013 04:25:12",
      "content": "<p>Is your Python compiled for 64 bits? If not, the 32 bit is not enough to read that file!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 29623,
      "author_name": "mjyhan",
      "author_url": "",
      "post_date": "08/28/2013 04:37:46",
      "content": "<p>You're right, thanks for the reminder. I installed the 32-bit version of Python(x,y) because of I used to have compatibility issues between 64-bit and Eclipse/PyDev. Not sure if the issues still exist, maybe I'll look into Spyder..</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 31050,
      "author_name": "ansuin",
      "author_url": "",
      "post_date": "09/17/2013 15:14:09",
      "content": "<p>I'm not an expert but I guess it could be a problem of the python version. I was helping a friend of mine which had the same problem on a 4GB laptop and with a brand new python installation (anaconda) everything worked well.</p>\n<p>&nbsp;</p>\n<p>&nbsp;</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 33335,
      "author_name": "julietsengcrank",
      "author_url": "",
      "post_date": "11/06/2013 21:30:01",
      "content": "",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "28069": "",
    "28076": "",
    "28097": "",
    "28112": "",
    "28175": "",
    "28176": "",
    "28189": "",
    "28344": "",
    "28381": "",
    "28383": "",
    "28404": "",
    "28533": "",
    "28536": "",
    "29613": "",
    "29620": "",
    "29622": "",
    "29623": "",
    "31050": "",
    "33335": ""
  },
  "source": "meta"
}