Now that we have discussed a few kinds of Linear Regression, it's time to move into non-linear regression. Like your time at school, the easiest stepping stone is Polynomials.

Just for revision, polynomials are rational expressions that follow the format:

$$ y=\theta_1x+\theta_2x^2+\theta_3x^3+\dots+\theta_nx^n $$

Depending on whatever value of $n$ you use

Often, polynomial functions can fit data better because they're capable of producing more complex curves, like so:

Source: CK-12

Source: CK-12

With polynomial regression, we want to produce a polynomial model that fits the data well, just like we did with linear regression.

2 Questions about the polynomial model

1. What is $n$?

Essentially, we have to decide what degree of polynomial you want to use to model the data. This can be a matter of trying out the possibilities, but sklearn makes it easy to do this. However, make sure you don't choose too large of a value for $n$ because that can easily cause your model to overfit by introducing too much complexity. For example, a simple linear regression would probably be sufficient in the below example. However, when you run polynomial regression on the data with a high $n$, you can create curves that don't generalize to new data very well:

Source: Wikipedia

Source: Wikipedia

2. What parameters do we want?

This we'll deal with the way we have always dealt with parameters, so that's not a big deal.