Paul's Python CoursePPC

Polynomial features

Not met yet

Polynomial features let linear regression fit curves. Give it columns x ** 0, x ** 1, x ** 2 and so on up to x ** degree, and least squares finds a weight for each; the model is still linear in its weights, so nothing else changes. Degree 1 is a straight line, and a degree d table has d + 1 columns, counting the column of ones that does the job of b. Higher degrees bend more, which is not always a good thing.

Try it

main.py

Output

Press Run and what your program prints shows up here.

Easy to get wrong

  • Thinks a straight line always has the lowest error on the points it was fitted to.
  • Thinks fitting a curve needs a different method from linear regression, rather than extra columns of powers.
  • Thinks a polynomial of degree 3 has three columns, forgetting the column of ones, x to the power 0.

Where it comes up