Skip to main content

    Thinking Dictionary

    Overfitting

    What it is

    Overfitting is when a model learns the accidents in its data along with the real pattern. It matches the past very well but predicts new cases badly.¹˒²

    A model here is a rule or formula built from data to make predictions. The data used to build it are the training data. The real test is new data, cases the model has never seen.¹

    An overfitted model follows the noise too closely.¹ Noise is the random up-and-down that is not part of the real pattern, as the Signal vs noise entry explains. The model mistakes one sample's quirks for real patterns, so it fails in future samples.²

    Why it matters

    Forecasts, apps and AI tools all predict from past data. A model that fits the past perfectly can be the overfitted one.¹ The Scientific models entry says a good model must predict new data. Overfitting is one reason a model fails that test.

    Why a perfect fit can be a bad sign

    Flexibility is how freely a model can bend to follow the data. More predictors, the pieces of information used to predict, or wigglier curves add flexibility.¹˒²

    As flexibility rises, error on the training data keeps falling. Error on new data falls at first, then levels off, then rises again, making a U-shape.¹

    Two forces make the U. A too-rigid model, like a straight line through a curved pattern, misses part of reality. That is bias. A model that is too jumpy would change a lot if built from a different sample. That is variance.¹ The goal is the low point of the U. The Occam's razor entry looks at the same tension from the side of simplicity.

    A model almost always does a bit worse on new data, and that alone is not overfitting. Overfitting means a less flexible model would have predicted better.¹ It is asking too much of the data: every predictor tried, at any stage, uses up some of what the data can support.²

    How to check: hold some data back

    The simplest check is a holdout. Split the data at random into two parts. Build the model on one part, then measure its errors on the other.¹ But one split can give a lucky or unlucky result, depending on which cases land where.¹

    Cross-validation repeats the idea. Cut the data into, say, 5 or 10 slices. Each slice takes a turn as the test set while the model is built on the rest, and the errors are averaged.¹

    Even this can be fooled: keep tuning a model to its cross-validation score, and you can overfit that score too.³

    Google Flu Trends

    In 2009, Google researchers reported that certain search queries tracked doctor visits for flu-like illness closely, allowing weekly US flu estimates with about a one-day delay.⁴

    Lazer and colleagues described the method as picking the best matches among 50 million search terms to fit 1,152 data points.⁵ The developers had to weed out terms that rose and fell with the seasons, as flu does, but had nothing to do with flu, such as high school basketball. Lazer's team said that should have been a warning sign of overfitting.⁵ The Multiple comparisons entry explains why searching that many options is risky.

    Two separate failures followed. In 2009, the original model underestimated flu-like illness during the first wave of a pandemic that began in summer, not winter.⁶ Lazer's team summed it up as "part flu detector, part winter detector".⁵ Researchers studying 2009, one of them from Google, blamed changed search habits and the unusual timing. They did not name overfitting as a cause.⁶

    Later, an updated model ran too high. From August 2011 to September 2013, it reported too much flu in 100 of 108 weeks.⁵ Even three-week-old data from the US Centers for Disease Control and Prevention (CDC) predicted current flu better.⁵

    Overfitting was one reason experts gave for the original model's troubles.⁵ For the later overestimates, Lazer's team mainly blamed changes to Google's search engine and to how people searched.⁵

    In everyday life

    These examples are hypothetical.

    • The lucky study routine. Your three best exam scores came after studying on a Tuesday, in the library, with green tea, after a short walk. A rule needing all four fits your past perfectly but probably copies chance. "I do better after a full review session" may predict the next exam better.
    • Commute time. With 12 factors noted on only 10 days, you can explain every past commute and still predict the next one badly.

    The common trap

    The trap is picking the model that fits the past best without ever testing it on data it has not seen.¹ A second trap is thinking big data rules overfitting out. Google Flu Trends had millions of candidate terms but only 1,152 data points.⁵

    A way out: ask whether a model was tested on data it had not seen, and whether it beats a simple rule, such as the average.

    Try it

    For 8 weeks, log how long one weekly chore takes. Use weeks 1 to 6 to write a prediction rule, as detailed as you like. Then, without changing it, test it on weeks 7 and 8. Did your rule beat the simple average of weeks 1 to 6?

    Related concepts

    Signal vs noise · Scientific models · Occam's razor · Multiple comparisons · Internal and external validity · Proxy measure · Baseline · Extrapolation

    Sources

    1. James, G., Witten, D., Hastie, T., & Tibshirani, R. (2021). An introduction to statistical learning: With applications in R (2nd ed.). Springer. doi:10.1007/978-1-0716-1418-1

    2. Babyak, M. A. (2004). What you see may not be what you get: A brief, nontechnical introduction to overfitting in regression-type models. Psychosomatic Medicine, 66(3), 411–421. doi:10.1097/01.psy.0000127692.23278.a9

    3. Cawley, G. C., & Talbot, N. L. C. (2010). On over-fitting in model selection and subsequent selection bias in performance evaluation. Journal of Machine Learning Research, 11(70), 2079–2107. JMLR: Cawley & Talbot 2010

    4. Ginsberg, J., Mohebbi, M. H., Patel, R. S., Brammer, L., Smolinski, M. S., & Brilliant, L. (2009). Detecting influenza epidemics using search engine query data. Nature, 457(7232), 1012–1014. doi:10.1038/nature07634

    5. Lazer, D., Kennedy, R., King, G., & Vespignani, A. (2014). The parable of Google Flu: Traps in big data analysis. Science, 343(6176), 1203–1205. doi:10.1126/science.1248506

    6. Cook, S., Conrad, C., Fowlkes, A. L., & Mohebbi, M. H. (2011). Assessing Google Flu Trends performance in the United States during the 2009 influenza virus A (H1N1) pandemic. PLoS ONE, 6(8), e23610. doi:10.1371/journal.pone.0023610