When finding a good model, sometimes we face under fitting and over fitting. The first example is borrowed; you can download the program at http://scikit-learn.org/stable/auto_examples/model_selection/plot_underfitting_overfitting.html#sphx-glr-auto-examples-model-selection-plot-underfitting-overfitting-py. It demonstrates the problems of under fitting and over fitting and how we can use linear regression with polynomial features to approximate nonlinear functions. The true function is given here:

In the following program, we try to use linear and polynomial models to approximate the equation. The slightly modified code is shown here. The program tries to show the impact of different models in terms of under-fitting and over-fitting:
import sklearn
import numpy as np
import matplotlib.pyplot as plt
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import...