Derive the number of monomial features of degree at most in input variables, using a stars-and-bars counting argument. Check it for by listing the terms, then evaluate it for and explain why a polynomial kernel avoids building these features?
Foundations, Feature engineering
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can turn a counting argument into a formula and see why explicit polynomial expansion blows up.
Key idea
Add a dummy variable . Each monomial of degree at most in matches exactly one choice of non-negative exponents . Stars and bars counts those solutions as .
Steps
- This is the harder companion of `polynomial-feature-dimension-count`, which states the formula. Take a monomial with . Define and attach with . This is a one-to-one match with the solutions of in non-negative integers.
- Count the solutions with stars and bars. Write stars in a row and place bars among them to split the stars into groups (the exponents). That means choosing the bar positions among slots, so
- Check with , : the terms are , which is 6, and .
- Evaluate for , : features (including the constant). For , it is .
- Why a kernel helps. The polynomial kernel equals the inner product of the full feature vectors (with suitable fixed weights on each monomial) but costs to evaluate, not with here. With training points you work with the kernel matrix instead.
Common mistakes
- Using . That counts only monomials of exact degree and leaves out lower-degree terms and the constant.
- Counting ordered products, which counts and separately.
- Thinking that the kernel trick changes the model. It computes the same inner products without writing out the features.
How long your answer should be
Half a page; about 3 minutes, including the check for , .
Read this
Previous in Foundations: Suppose the fold errors in cross-validation each have variance and every pair has correlation . Derive the variance of their average. Evaluate it for and with , and explain why this is used to argue that leave-one-out has high variance?
Next in Foundations: What does the no-free-lunch theorem say, and what does it imply for choosing a learning algorithm in practice?