# Why can't algorithms avoid overfitting themselves?

So, I understand overfitting (bonus question: precise statistical definition of overfitting?). You don't want to match the noise in your sample.

What I don't understand is why this requires a human to hide data from the algorithm. Doesn't this imply that you don't have the best algorithm to begin with if extra information will make your model worse? I know that you could program the computer to compute the AIC/BIC/etc and hide info from itself, but it still seems like more information shouldn't make models worse.

Put another way, removing a variable is equivalent to hardcoding its coefficient to zero. It seems quite strange that for all these variables, exactly zero would happen to be best coefficient estimate given the available data. Surely, given some information, we could improve upon this naive guess, even if only a tiny bit.

Why don't we have algorithms which can produce models involving all the variables, even those whose effect size is too small to be reliably detected from the sample, and estimate a coefficient for them without overfitting and making the fit on the holdout set worse?

Why can't algorithms avoid overfitting themselves?

They can. If you design an algorithm that implements model selection based on cross-validation or information criteria, you should achieve a good balance between overfitting and underfitting.

What I don't understand is why this requires a human to hide data from the algorithm. Doesn't this imply that you don't have the best algorithm to begin with if extra information will make your model worse?

In the above setup, all information would be used for selecting the model and all or some information would be used for estimating it. (All - if the selected model contains all variables, some - if the selected model excludes some variables. See also the note on ridge regression and $$L_2$$ regularization below.)

I know that you could program the computer to compute the AIC/BIC/etc and hide info from itself, but it still seems like more information shouldn't make models worse.

Consider AIC- or BIC-based model selection, e.g. in the context of multiple linear regression. All of the data is used for training, yet the selected model (under some assumptions) offers an optimal (in a well-defined sense which differs for AIC vs. BIC vs. ...) balance between over- and underfitting.

Why don't we have algorithms which can produce models involving all the variables, even those whose effect size is too small to be reliably detected from the sample, and estimate a coefficient for them without overfitting and making the fit on the holdout set worse?

Variable selection is just one way of fighting overfitting; regularization is another, e.g. ridge regression or a neural network trained using $$L^2$$ regularization. When using regularization, the intensity can be determined via cross validation or via information criteria. There again, all data is used for training.

Overfitting: Predicitng much worse on test data than training data. i.e. Does not generalize outside of particular data used to train model. Which means if it can't predict outside of data used to train, it probably doesn't explain much about the process used to generate either datasets.

I suggest you read/watch Statistical Rethinking by McElreath. He shows throughout how making extremely flexible models usually isn't useful for explaining. And even for prediction, one needs to temper the flexibility so as to predict outside of training data. It is not hard to make a model that perfectly predicts training data. Simply add enough parameters as data points. And voila $$R^2$$ = 1. Try to use this model on a new dataset generated from the same process as original training dataset, can you imagine what would happen? So what does this hypothetical model accomplish? A re description of original data. No abstraction, no synthesis, no real learning, maybe data condensing.

To clarify a few things:

• When you say hide information from the model, that's not really always the case. It is true that splitting into a training/test dataset does this. However, using information criteria to estimate out of sample predictive accuracy does not require hiding information from the model.
• Saying 'making the model worse' in this context assumes the metric you are trying to optimize is in sample error of some type. Think about the above silly example of a model with as many parameters as data points. You are not trying to find the model with the best $$R^2$$, at least you shouldn't be.
• This sounds more like a comment than an answer: you define the term and then refer to a source. Consider either converting this to a comment or expanding w.r.t. the content of the source you are referring to. – Richard Hardy Nov 1 '19 at 15:57
• Much better now, thank you. Now what about answers to the actual questions like Why can't algorithms avoid overfitting themselves?, why this requires a human to hide data from the algorithm and Why don't we have algorithms which can produce models involving all the variables, even those whose effect size is too small to be reliably detected from the sample, and estimate a coefficient for them without overfitting and making the fit on the holdout set worse? – Richard Hardy Nov 1 '19 at 16:29
• I upvoted your answers to those questions, as I thought you did a good and thorough enough job. I am addressing the first question and adding material to help clarify to make the additional questions not needed anymore. Especially in light of your answers, which conclusively answer. – MindtheData Nov 1 '19 at 17:09
• Thank you for the clarification. – Richard Hardy Nov 1 '19 at 17:21