Derive the number of monomial features of degree at most p in d input variables, using a stars-and-bars counting argument. Check it for d=2, p=2 by listing the terms, then evaluate it for d=100, p=3 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 x0=1. Each monomial of degree at most p in x1,…,xd matches exactly one choice of non-negative exponents α0+α1+⋯+αd=p. Stars and bars counts those solutions as (d+pp).

Steps

  1. This is the harder companion of `polynomial-feature-dimension-count`, which states the formula. Take a monomial x1α1⋯xdαd with α1+⋯+αd≤p. Define α0=p−∑j≥1αj≥0 and attach x0α0 with x0=1. This is a one-to-one match with the solutions of α0+α1+⋯+αd=p in non-negative integers.
  2. Count the solutions with stars and bars. Write p stars in a row and place d bars among them to split the stars into d+1 groups (the exponents). That means choosing the d bar positions among p+d slots, so D=(d+pd)=(d+pp).
  3. Check with d=2, p=2: the terms are 1, x1, x2, x12, x1x2, x22, which is 6, and (42)=6.
  4. Evaluate for d=100, p=3: (1033)=103⋅102⋅1016=176,851 features (including the constant). For d=10, p=3 it is 286.
  5. Why a kernel helps. The polynomial kernel k(x,z)=(1+x⊤z)p equals the inner product of the full feature vectors (with suitable fixed weights on each monomial) but costs O(d) to evaluate, not O(D) with D≈1.8×105 here. With n training points you work with the n×n kernel matrix instead.

Common mistakes

How long your answer should be

Half a page; about 3 minutes, including the check for d=2, p=2.

Read this

Previous in Foundations: Suppose the m fold errors in cross-validation each have variance σ2 and every pair has correlation ρ. Derive the variance of their average. Evaluate it for m=10 and ρ=0.1, 0.5, 0.9 with σ2=1, 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?