{
  "id": 11412,
  "title": "SGD learning rate question",
  "url": "/competitions/datasciencebowl/discussion/11412",
  "author_name": "",
  "post_date": "2015-01-02T02:54:40.587Z",
  "votes": null,
  "comment_count": 3,
  "views": 1978,
  "content": "<p>I'm new to machine learning and I'd like to confirm that I'm debugging in the right direction.</p>\n<p>When training my model using SGD I get fluctuations in the prediction error, which is to be expected, but my fluctuations seem very large. For example, here are my miss-class percentages for each epoch:</p>\n<p>1.0<br>0.34<br>0.71<br>0.10<br>0.10<br>0.75<br>0.58<br>0.87<br>0.96<br>0.41<br>(training is still completing...)<br><br>The fact that the error goes down to 0.34 after just one epoch and then jumps from 0.10 to 0.75, then up to 0.96 seems like a lot of useless scattering about and I would expect smaller jumps with an overall downward trend.</p>\n<p>Is this normal behavior when using SGD? I'm wondering if this is due to using too high a learning rate, or an incorrect momentum?</p>",
  "messages": [
    {
      "id": "62199",
      "postDate": "01/02/2015 02:54:40",
      "content": "<p>I'm new to machine learning and I'd like to confirm that I'm debugging in the right direction.</p>\n<p>When training my model using SGD I get fluctuations in the prediction error, which is to be expected, but my fluctuations seem very large. For example, here are my miss-class percentages for each epoch:</p>\n<p>1.0<br>0.34<br>0.71<br>0.10<br>0.10<br>0.75<br>0.58<br>0.87<br>0.96<br>0.41<br>(training is still completing...)<br><br>The fact that the error goes down to 0.34 after just one epoch and then jumps from 0.10 to 0.75, then up to 0.96 seems like a lot of useless scattering about and I would expect smaller jumps with an overall downward trend.</p>\n<p>Is this normal behavior when using SGD? I'm wondering if this is due to using too high a learning rate, or an incorrect momentum?</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62218",
      "postDate": "01/02/2015 15:53:14",
      "content": "<p>By nature SGD will have a tendency to oscillate. If the oscillation is very pronounced it might be because you use a too big learning rate.</p>\n<p>Decreasing the learning rate when the algorithm runs allow to diminish the oscillation.</p>\n\n<p>Source: http://cs229.stanford.edu/notes/cs229-notes1.pdf&nbsp;</p>\n<p>Note however that it may never &#8220;converge&#8221; to the minimum,&nbsp;and <strong>the parameters &#952; will keep oscillating around the minimum of J(&#952;)</strong>; but&nbsp;in practice most of the values near the minimum will be reasonably good&nbsp;approximations to the true minimum.2</p>\n<p>While it is more common to run stochastic gradient descent as we have described it<br>and with a fixed learning rate &#945;, <strong>by slowly letting the learning rate &#945; decrease to zero as</strong><br><strong>the algorithm runs, it is also possible to ensure that the parameters will converge to the</strong><br><strong>global minimum rather then merely oscillate around the minimum</strong>.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62219",
      "postDate": "01/02/2015 18:01:48",
      "content": "<p>[quote=jstaker7;62199]</p>\n<p>For example, here are my miss-class percentages for each epoch:</p>\n<p>1.0<br>0.34<br>0.71<br>0.10</p>\n<p>[/quote]</p>\n<p>These look very chaotic and also a bit too good to be true - I don't think you could really get to 0.10 misclassification by a random overshoot caused by too high a learning rate. Are you certain these are per <em>epoch&nbsp;</em>numbers? They look more like per batch numbers with a relatively small batch size. When you happen to hit a batch that is pretty easy to classify, the accuracy goes way up. Then the network sees a harder batch and it drops back down.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "62327",
      "postDate": "01/06/2015 04:27:54",
      "content": "<p>Hi James and Alexandre,</p>\n<p>Sorry for the delay in commenting, it took me quite a bit of time to root out the problem. Your comments were both extremely helpful in pointing me in the right direction and I ultimately solved the problem.</p>\n<p>I used to consider batch size as a not very important hyper parameter, and only important for managing computational resources, but I was wrong! I now know that it can significantly impact learning.&nbsp;</p>\n<p>Thank you!</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 62218,
      "author_name": "alexandrekowalczyk",
      "author_url": "",
      "post_date": "01/02/2015 15:53:14",
      "content": "<p>By nature SGD will have a tendency to oscillate. If the oscillation is very pronounced it might be because you use a too big learning rate.</p>\n<p>Decreasing the learning rate when the algorithm runs allow to diminish the oscillation.</p>\n\n<p>Source: http://cs229.stanford.edu/notes/cs229-notes1.pdf&nbsp;</p>\n<p>Note however that it may never &#8220;converge&#8221; to the minimum,&nbsp;and <strong>the parameters &#952; will keep oscillating around the minimum of J(&#952;)</strong>; but&nbsp;in practice most of the values near the minimum will be reasonably good&nbsp;approximations to the true minimum.2</p>\n<p>While it is more common to run stochastic gradient descent as we have described it<br>and with a fixed learning rate &#945;, <strong>by slowly letting the learning rate &#945; decrease to zero as</strong><br><strong>the algorithm runs, it is also possible to ensure that the parameters will converge to the</strong><br><strong>global minimum rather then merely oscillate around the minimum</strong>.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62219,
      "author_name": "jfkingiii",
      "author_url": "",
      "post_date": "01/02/2015 18:01:48",
      "content": "<p>[quote=jstaker7;62199]</p>\n<p>For example, here are my miss-class percentages for each epoch:</p>\n<p>1.0<br>0.34<br>0.71<br>0.10</p>\n<p>[/quote]</p>\n<p>These look very chaotic and also a bit too good to be true - I don't think you could really get to 0.10 misclassification by a random overshoot caused by too high a learning rate. Are you certain these are per <em>epoch&nbsp;</em>numbers? They look more like per batch numbers with a relatively small batch size. When you happen to hit a batch that is pretty easy to classify, the accuracy goes way up. Then the network sees a harder batch and it drops back down.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 62327,
      "author_name": "jstaker7",
      "author_url": "",
      "post_date": "01/06/2015 04:27:54",
      "content": "<p>Hi James and Alexandre,</p>\n<p>Sorry for the delay in commenting, it took me quite a bit of time to root out the problem. Your comments were both extremely helpful in pointing me in the right direction and I ultimately solved the problem.</p>\n<p>I used to consider batch size as a not very important hyper parameter, and only important for managing computational resources, but I was wrong! I now know that it can significantly impact learning.&nbsp;</p>\n<p>Thank you!</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "62199": "",
    "62218": "",
    "62219": "",
    "62327": ""
  },
  "source": "meta"
}