Machine-learning 5 minutes

# Polynomial basis expansion

Polynomial basis expansion, also called polynomial features augmentation, is part of the machine-learning preprocessing. It consists in adding powers of the input’s components to the input vector.

## Example

Let $\dataset$ be a dataset for a machine-learning task. As usual, $\dataset$ is made of $\ndataset$ pairs of input vectors $\ninputvec{\idataset}$ and output value $\ioutputval{\idataset}$:

For clarity, suppose the dimensionality is two: $\ninputvec{\idataset} \in \realset^2$.

The polynomial augmentation of degree $2$ for the input vector $\ninputvec{\idataset}$:

Is the vector $\Phi_2(\ninputvec{\idataset})$:

Likewise, the degree $3$ augmentation is:

and so on…

## Polynomial regression and linear models

Polynomial inputs augmentation enriches the expressive power of linear models. Indeed, a polynomial regression of degree $d$ is simply a linear regression on the augmented inputs.

In other words, to fit the polynomial $P(x)$:

To a dataset $\dataset = \{(\ninputvec{\idataset}, \ioutputval{\idataset}) \mid \idataset \leq \ndataset\}$, it is enough to fit a linear function $\linmodel{a}$ to the augmented dataset:

This is why a polynomial regression is a linear regression.

## Notations

To keep the notations simple, we often consider that the polynomial inputs augmentation is done in the preprocessing and we note $\inputvec$ to denote the augmented vector $\Phi_d(\inputvec)$.

## How much richer does linear regression become?

Very much! By the Stone-Weierstrass theorem (wikipedia link), every continuous function $\model$ can be uniformly approximated (as closely as desired) by a polynomial function on a closed interval.

Since our dataset is discrete, this means that whatever the relationship $\truemodel$ between the inputs and the outputs, we can get as close as we want using polynomials (as long as the degree $d$ is big enough).

Actually, since the train set is finite, we can always find a polynomial of degree $d = \ndataset-1$ that goes through every points in the train set. This means that for $d = \ndataset-1$, we can make the train error to be $0$. This is called the Lagrange polynomial interpolation (wikipedia link).

Wait… we can make the train error to be $0$? Yes, but…

## So, is it the ultimate machine-learning technique?

No, because…

Polynomial regressions of high degree tend to overfit. If you’re not sure what that means, check out my dedicated article, which is completely writen and illustrated using polynomial regressions: overfiting. The regression matrix $X$ that we have to inverse grows linearly as the regression’s degree $d$ grows (since it has $\ndataset d$ rows). This yields computational complications.

Numerical errors accumulate when we take the power of a number: large powers of small values are rounded to $0$ in floating point arithmetic. So even is there exists a mathematical solution, we might not be able to implement it.