Machine Learning 101: What Is Regularization?
An interesting thing about this article, potentially misleading to beginners trying to understand various machine learning and stats techniques, is that despite what the article says, it is not apparent at all that the polynomial model of degree 3 &#x27;&quot;sticks&quot; to the data but does not describe the underlying relationship of the data points&#x27;.<p>On the contrary...for this toy example, doesn&#x27;t it look pretty good!  There&#x27;s really not enough information here to decide whether the model is actually over-fitting or not, and this can easily mislead the beginner into wondering &quot;just why the hell are we taking that awesome model and doing some regularisation thingy to choose a worse model...which is then...better?&quot;<p>To truly understand, you&#x27;ve got to tackle:<p>1. What is overfitting?
2. Why&#x2F;when are too many parameters a problem?<p>Now...i don&#x27;t know how intuitive this is for others, but I like to tell people that over-fitting is a fancy word for &quot;projecting too much about the general from the specific&quot;.<p>So why does that matter and what does it have to do with too many parameters?<p>Well lets say you&#x27;ve got a sample of men and women, and in this case, you&#x27;re trying to predict underlying rates of breast and testicular cancer (i&#x27;m assuming these are primarily gender related for my example), and the &quot;real&quot; relationship is indeed just gender: whether the person is male or female determines the basic underlying risks of these cancers.  That&#x27;s not very many variables for your model.  But lets say, in your sample, several of the people with testicular cancer are named &quot;Bob&quot; and several of the people with breast cancer are named &quot;Mary&quot; so you add more variables, binary variables, which indicate whether a person is called &quot;Bob&quot;, and whether a person is called &quot;Mary&quot;, and suddenly your model prediction amongst your sample for cancer goes through the roof...and yet when you apply it to the population at large, not only did it not predict cancer any better...but suddenly there are all these angry letters from Bobs and Marys who were told they might have cancer.  In fact, its doing worse than if you hadn&#x27;t included those variables at all.  What&#x27;s going on?  You overfit.<p>So you see, in many models, adding in more and more variables can lead you to do better in your sample, but at some point can actually make your model worse.  Why does this happen?<p>Actually, amongst many machine learning and statistical algorithms, there&#x27;s a pretty intuitive explanation...once its been explained to you.<p>Lets say that your model only had variables to indicate gender at first, and you come along and you throw in a handful more.  You&#x27;re judging your models performance on its prediction in your sample population.  What could many machine learning algorithms do here?  Well, for each new variable you introduce, one option is to do absolutely nothing.  And if the algorithm chooses to do nothing, what you&#x27;ve actually got is your original gender indicators: you&#x27;ve gained nothing, but you&#x27;ve lost nothing (well, albeit adding more parameter numbers and algorithmic inefficiency&#x2F;complexity).  But most (almost all) methods are not that precise or accurate.  So what else could happen?  Well, each parameter you add has a small random and statistical chance of increasing your models predictiveness in your sample.  We used the example of &quot;Bob&quot; and &quot;Mary&quot;, but the people with cancer in your sample could have all sorts of qualities, and as you just through more variables&#x2F;features at your algorithm, it will eventually hit some that, although having no explanatory power in the population at large, do correlate with statistical quirks of your sample. &quot;Blue eyes&quot;, &quot;four toes&quot;, &quot;bad breath&quot;, &quot;got a paycheck last week&quot; that sort of things.  Its a form of data-dredging and its far more widespread professionally than I&#x27;d like :P And if you keep throwing variables at it, eventually, many algorithms will choose to naively keep those characteristics that are overly specific to describing your sample, but don&#x27;t describe the population at large.<p>And that&#x27;s why we might want to &quot;regularise&quot;.  We want there to be a cost of adding variables to the model to make the phenomenon of including statistically spurious variables like this far more unlikely.  It is hoped that strong generalisable variables, like male&#x2F;female, will overcome this cost, while spurious ones added randomly or to game some metric will be less likely to pass that extra hurdle.  To use a signal analogy, by implementing a cost for adding more variables, you&#x27;re filtering out some of the statistical noise to get at the real-loud signal below.<p>Now, personal anecdote, even though you want to keep models simple (like code, ceteris paribus, and be suspicious of any machine learning&#x2F;AI technique that uses too many variables...), I don&#x27;t actually like regularisation often on the whole.  In the example, its not actually clear at all that this is a case of over-fitting, and so by following it, you might actually be making your model worse by using it.  And in the real world, there&#x27;s often a number of other techniques that work better (test&#x2F;train&#x2F;resampling).  But like all techniques, its another arrow in your quiver when the time is right.<p>And now I&#x27;ve written an essay.