Skip to content

Model Capacity and Overfitting Explained With Polynomials

A model's capacity is its ability to fit a wide variety of functions, and the set of functions it is allowed to choose from, its hypothesis space, controls it. Goodfellow, Bengio, and Courville put it this way in Section 5.2 of Deep Learning: "a model's capacity is its ability to fit a wide variety of functions. Models with low capacity may struggle to fit the training set. Models with high capacity can overfit by memorizing properties of the training set that do not serve them well on the test set." Their example: linear regression has the set of all linear functions as its hypothesis space, and adding powers of x as features, to get a quadratic or a degree-9 polynomial, increases the capacity.

They add the principle that matters in practice. Learning algorithms "will generally perform best when their capacity is appropriate for the true complexity of the task they need to perform and the amount of training data they are provided with." Models with insufficient capacity cannot solve complex tasks, and models with more capacity than the task needs may overfit.

Try it by hand. Four training points come from y = x² plus noise of ±0.5: (0, 0.5), (1, 0.5), (2, 4.5), and (3, 8.5). Fit three models by least squares and test each on fresh noiseless points x = 0.5, 1.5, and 2.5, where the true value is x². The line, which has low capacity, fits y = −0.7 + 2.8x. Its training mean squared error is 1.2, and its test error is 0.59. It underfits, because a line cannot bend. The quadratic y = 0.3 − 0.2x + x² has the right form for this data. Training error is 0.2, test error is 0.027. The cubic has four free coefficients, so it can pass through all four points exactly: y = 1/2 − (10/3)x + 4x² − (2/3)x³ (scores below use the exact coefficients, not rounded ones). Training error is 0, and test error is 0.167, about six times worse than the quadratic's. On these noisy points, the cubic's extra freedom went into the noise. All three fits were computed in exact fractions, and the data are invented.

So capacity is necessary but not sufficient. The cubic has enough capacity to fit the training set perfectly and still generalizes worse than the quadratic here, on this noisy sample and these three test points. A caution of my own, not from the section I read: the number of parameters is only a rough stand-in for capacity, because what a model can represent also depends on its form.

The trap: thinking that enough capacity guarantees success. It guarantees only that the model can represent the pattern, and it says nothing about whether the training data are enough to find the right one. More capacity than the data support can give you a model that fits the training set and fails outside it, as the cubic does on noisy points. With noiseless points from x², the same cubic would recover x² exactly.

Prof Rod's rule: choose the capacity to match the problem and the amount of data you have, and judge it on data it has not seen.

Goodfellow, Bengio, and Courville, Deep Learning, MIT Press, 2016, Section 5.2 Capacity, Overfitting and Underfitting, pp. 109–110