{
  "id": 4858,
  "title": "1% prediction rate: what am I doing wrong?",
  "url": "/competitions/digit-recognizer/discussion/4858",
  "author_name": "gdowding",
  "post_date": "2013-06-16T22:47:22.160000",
  "votes": 1,
  "comment_count": 3,
  "views": null,
  "content": "<p>Hi,<br>\r\n<br>\r\nI followed this tutorial for using Pandas and scikit learn to do data recognition. I was expecting to get a reasonable result, to start with, but I am getting about 1% accuracy. It makes me think I am doing something wrong.</p>\r\n<p>http://scikit-learn.org/dev/auto_examples/plot_digits_classification.html#example-plot-digits-classification-py</p>\r\n<p><br>\r\nI created a classifier with 1/3 of the available training data.</p>\r\n<pre>train_df = pd.read_csv('train.csv')\r\nclassifier = svm.SVC(gamma=0.001)\r\ntrain_size = train_df.shape[0] / 3\r\ntrain_start = 0\r\ntrain_set = train_df.ix[train_start:train_size]\r\nX = train_set.ix[0:, 1:]\r\ny = train_set.ix[0:, 0]\r\n%time classifier.fit(X, y)<code></code></pre>\r\n<p>When I run the classifier with some of the reserved data, I get around 1% accuracy. It looks like the classifier is classifying most of the samples as 1.</p>\r\n<pre>start = train_size &#43; 500\r\nlength = 25\r\n#print test_data\r\ntest_slice = test_data.ix[start:start &#43; length]\r\nexp_slice = expected.ix[start:start &#43; length]\r\n#print test_slice\r\n%time predicted = classifier.predict(test_slice)\r\n\r\nprint zip(exp_slice, predicted)<code></code></pre>\r\n<p>Here is the output</p>\r\n<pre>CPU times: user 0.32 s, sys: 0.01 s, total: 0.33 s\r\nWall time: 0.78 s\r\n[(9, 1), (8, 1), (5, 1), (2, 1), (5, 1), (2, 1), (1, 1), (3, 1), (2, 1), (1, 1), (2, 1), (2, 1), (0, 1), (9, 1), (1, 1), (3, 1), (1, 1), (0, 1), (0, 1), (4, 1), (6, 1), (3, 1), (3, 1), (4, 1), (3, 1), (3, 1)]</pre>\r\n<p><code></code><br>\r\nI feel like since the predictions are coming out as mostly 1's I am missing something pretty basic. Any help would be appreciated.</p>\r\n<p></p>\r\n<p>Thanks,</p>\r\n<p>George</p>",
  "messages": [
    {
      "id": 32359,
      "postDate": "2013-10-16T10:08:22.250Z",
      "content": "<p>Hi theharshest,</p>\n<p>I think this is best understood pictorially in the link you provided. But if you prefer it in textual terms, this would be what I try to think.</p>\n<p>A low gamma (= far reached) makes it so that more similar/ambiguous cases will be considered same/similar. e.g. a very poorly written 7 which is almost like 1 in a digit recognition task will be considered as a 1.</p>\n<p>A high gamma (= close reached) makes it so that only very similar/unambiguous case gets considered same/similar. e.g. two similar 1 digits are considered same/similar, but the same very poorly written 7 which is almost like 1 above would not be considered to be 1 in this case, because its shape is much less like a 1, after all.</p>\n<p>&nbsp;</p>\n<p>&nbsp;</p>",
      "votes": 2
    },
    {
      "id": 26293,
      "postDate": "2013-06-27T12:49:50.907Z",
      "content": "<p>Hi George,</p>\r\n<p>I see that you're using a gamma of 0.001 for your RBF kernel SVM instance. My experience with this competition is that this gamma is too big (and I guess it's not converging and spiraling out).</p>\r\n<p>In fact, I verified with my SVM code (rank 206) that with a gamma of 0.001 accuracy drops to 11% immediately. You may like to search for different gamma values. Using a smaller dataset (2000 instances) should be good for the search initially.</p>\r\n<p>Concretely:</p>\r\n<ol>\r\n<li>Create a smaller training set from the original training file </li><li>Try out different combinations of C and gamma (for RBF kernels) on a 75% training and 25% testing\r\n</li><li>Print out the results and observe how the gamma is good. </li></ol>\r\n<p>I hope this helps.</p>",
      "votes": 2
    },
    {
      "id": 25772,
      "postDate": "2013-06-16T22:47:22.160Z",
      "content": "<p>Hi,<br>\r\n<br>\r\nI followed this tutorial for using Pandas and scikit learn to do data recognition. I was expecting to get a reasonable result, to start with, but I am getting about 1% accuracy. It makes me think I am doing something wrong.</p>\r\n<p>http://scikit-learn.org/dev/auto_examples/plot_digits_classification.html#example-plot-digits-classification-py</p>\r\n<p><br>\r\nI created a classifier with 1/3 of the available training data.</p>\r\n<pre>train_df = pd.read_csv('train.csv')\r\nclassifier = svm.SVC(gamma=0.001)\r\ntrain_size = train_df.shape[0] / 3\r\ntrain_start = 0\r\ntrain_set = train_df.ix[train_start:train_size]\r\nX = train_set.ix[0:, 1:]\r\ny = train_set.ix[0:, 0]\r\n%time classifier.fit(X, y)<code></code></pre>\r\n<p>When I run the classifier with some of the reserved data, I get around 1% accuracy. It looks like the classifier is classifying most of the samples as 1.</p>\r\n<pre>start = train_size &#43; 500\r\nlength = 25\r\n#print test_data\r\ntest_slice = test_data.ix[start:start &#43; length]\r\nexp_slice = expected.ix[start:start &#43; length]\r\n#print test_slice\r\n%time predicted = classifier.predict(test_slice)\r\n\r\nprint zip(exp_slice, predicted)<code></code></pre>\r\n<p>Here is the output</p>\r\n<pre>CPU times: user 0.32 s, sys: 0.01 s, total: 0.33 s\r\nWall time: 0.78 s\r\n[(9, 1), (8, 1), (5, 1), (2, 1), (5, 1), (2, 1), (1, 1), (3, 1), (2, 1), (1, 1), (2, 1), (2, 1), (0, 1), (9, 1), (1, 1), (3, 1), (1, 1), (0, 1), (0, 1), (4, 1), (6, 1), (3, 1), (3, 1), (4, 1), (3, 1), (3, 1)]</pre>\r\n<p><code></code><br>\r\nI feel like since the predictions are coming out as mostly 1's I am missing something pretty basic. Any help would be appreciated.</p>\r\n<p></p>\r\n<p>Thanks,</p>\r\n<p>George</p>",
      "votes": 1
    },
    {
      "id": 32355,
      "postDate": "2013-10-16T09:35:24.967Z",
      "content": "<p>Hi,</p>\n<p>I'm also trying different values of gamma here, but don't understand its significance as such. From http://scikit-learn.org/stable/auto_examples/svm/plot_rbf_parameters.html, I can see that -</p>\n<p><em><strong>the gamma parameter defines how far the influence of a single training example reaches, with low values meaning &#8216;far&#8217; and high values meaning &#8216;close&#8217;</strong></em></p>\n<p>But I don't understand what does that mean. Can you please explain?</p>\n<p>Thank you.</p>"
    }
  ],
  "comments": [
    {
      "id": 32359,
      "author_name": "Log0",
      "author_url": "",
      "post_date": "2013-10-16T10:08:22.250000",
      "content": "<p>Hi theharshest,</p>\n<p>I think this is best understood pictorially in the link you provided. But if you prefer it in textual terms, this would be what I try to think.</p>\n<p>A low gamma (= far reached) makes it so that more similar/ambiguous cases will be considered same/similar. e.g. a very poorly written 7 which is almost like 1 in a digit recognition task will be considered as a 1.</p>\n<p>A high gamma (= close reached) makes it so that only very similar/unambiguous case gets considered same/similar. e.g. two similar 1 digits are considered same/similar, but the same very poorly written 7 which is almost like 1 above would not be considered to be 1 in this case, because its shape is much less like a 1, after all.</p>\n<p>&nbsp;</p>\n<p>&nbsp;</p>",
      "votes": 2,
      "replies": []
    },
    {
      "id": 26293,
      "author_name": "Log0",
      "author_url": "",
      "post_date": "2013-06-27T12:49:50.907000",
      "content": "<p>Hi George,</p>\r\n<p>I see that you're using a gamma of 0.001 for your RBF kernel SVM instance. My experience with this competition is that this gamma is too big (and I guess it's not converging and spiraling out).</p>\r\n<p>In fact, I verified with my SVM code (rank 206) that with a gamma of 0.001 accuracy drops to 11% immediately. You may like to search for different gamma values. Using a smaller dataset (2000 instances) should be good for the search initially.</p>\r\n<p>Concretely:</p>\r\n<ol>\r\n<li>Create a smaller training set from the original training file </li><li>Try out different combinations of C and gamma (for RBF kernels) on a 75% training and 25% testing\r\n</li><li>Print out the results and observe how the gamma is good. </li></ol>\r\n<p>I hope this helps.</p>",
      "votes": 2,
      "replies": []
    },
    {
      "id": 32355,
      "author_name": "theharshest",
      "author_url": "",
      "post_date": "2013-10-16T09:35:24.967000",
      "content": "<p>Hi,</p>\n<p>I'm also trying different values of gamma here, but don't understand its significance as such. From http://scikit-learn.org/stable/auto_examples/svm/plot_rbf_parameters.html, I can see that -</p>\n<p><em><strong>the gamma parameter defines how far the influence of a single training example reaches, with low values meaning &#8216;far&#8217; and high values meaning &#8216;close&#8217;</strong></em></p>\n<p>But I don't understand what does that mean. Can you please explain?</p>\n<p>Thank you.</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "32359": "",
    "26293": "",
    "25772": "",
    "32355": ""
  }
}