# Regression Week 3: Assessing Fit (polynomial regression)

In this notebook you will compare different regression models in order to assess which model fits best. We will be using polynomial regression as a means to examine this topic. In particular you will:

• Write a function to take an SArray and a degree and return an SFrame where each column is the SArray to a polynomial value up to the total degree e.g. degree = 3 then column 1 is the SArray column 2 is the SArray squared and column 3 is the SArray cubed
• Use matplotlib to visualize polynomial regressions
• Use matplotlib to visualize the same polynomial degree on different subsets of the data
• Use a validation set to select a polynomial degree
• Assess the final fit using test data

We will continue to use the House data from previous notebooks.

# Fire up graphlab create

``````

In [1]:

import graphlab

``````

Next we're going to write a polynomial function that takes an SArray and a maximal degree and returns an SFrame with columns containing the SArray to all the powers up to the maximal degree.

The easiest way to apply a power to an SArray is to use the .apply() and lambda x: functions. For example to take the example array and compute the third power we can do as follows: (note running this cell the first time may take longer than expected since it loads graphlab)

``````

In [4]:

tmp = graphlab.SArray([1., 2., 3.])
tmp_cubed = tmp.apply(lambda x: x**3)
print tmp
print tmp_cubed
print tmp*tmp

``````
``````

[1.0, 2.0, 3.0]
[1.0, 8.0, 27.0]
[1.0, 4.0, 9.0]

``````

We can create an empty SFrame using graphlab.SFrame() and then add any columns to it with ex_sframe['column_name'] = value. For example we create an empty SFrame and make the column 'power_1' to be the first power of tmp (i.e. tmp itself).

``````

In [3]:

ex_sframe = graphlab.SFrame()
ex_sframe['power_1'] = tmp
print ex_sframe

``````
``````

+---------+
| power_1 |
+---------+
|   1.0   |
|   2.0   |
|   3.0   |
+---------+
[3 rows x 1 columns]

``````

# Polynomial_sframe function

Using the hints above complete the following function to create an SFrame consisting of the powers of an SArray up to a specific degree:

``````

In [5]:

def polynomial_sframe(feature, degree):
# assume that degree >= 1
# initialize the SFrame:
poly_sframe = graphlab.SFrame()
# and set poly_sframe['power_1'] equal to the passed feature
poly_sframe['power_1'] = feature
# first check if degree > 1
if degree > 1:
# then loop over the remaining degrees:
# range usually starts at 0 and stops at the endpoint-1. We want it to start at 2 and stop at degree
for power in range(2, degree+1):
# first we'll give the column a name:
name = 'power_' + str(power)
name_left = 'power_' + str(power-1)
# then assign poly_sframe[name] to the appropriate power of feature
poly_sframe[name] = feature * poly_sframe[name_left]

return poly_sframe

``````

To test your function consider the smaller tmp variable and what you would expect the outcome of the following call:

``````

In [6]:

print polynomial_sframe(tmp, 3)

``````
``````

+---------+---------+---------+
| power_1 | power_2 | power_3 |
+---------+---------+---------+
|   1.0   |   1.0   |   1.0   |
|   2.0   |   4.0   |   8.0   |
|   3.0   |   9.0   |   27.0  |
+---------+---------+---------+
[3 rows x 3 columns]

``````

# Visualizing polynomial regression

Let's use matplotlib to visualize what a polynomial regression looks like on some real data.

``````

In [7]:

sales = graphlab.SFrame('kc_house_data.gl/')

``````

As in Week 3, we will use the sqft_living variable. For plotting purposes (connecting the dots), you'll need to sort by the values of sqft_living. For houses with identical square footage, we break the tie by their prices.

``````

In [8]:

sales = sales.sort(['sqft_living', 'price'])

``````

Let's start with a degree 1 polynomial using 'sqft_living' (i.e. a line) to predict 'price' and plot what it looks like.

``````

In [9]:

poly1_data = polynomial_sframe(sales['sqft_living'], 1)
poly1_data['price'] = sales['price'] # add price to the data since it's the target

``````

NOTE: for all the models in this notebook use validation_set = None to ensure that all results are consistent across users.

``````

In [10]:

model1 = graphlab.linear_regression.create(poly1_data, target = 'price', features = ['power_1'], validation_set = None)

``````
``````

Linear regression:

--------------------------------------------------------

Number of examples          : 21613

Number of features          : 1

Number of unpacked features : 1

Number of coefficients    : 2

Starting Newton Method

--------------------------------------------------------

+-----------+----------+--------------+--------------------+---------------+

| Iteration | Passes   | Elapsed Time | Training-max_error | Training-rmse |

+-----------+----------+--------------+--------------------+---------------+

| 1         | 2        | 1.035530     | 4362074.696077     | 261440.790724 |

+-----------+----------+--------------+--------------------+---------------+

SUCCESS: Optimal solution found.

``````
``````

In [11]:

#let's take a look at the weights before we plot
model1.get("coefficients")

``````
``````

Out[11]:

name
index
value
stderr

(intercept)
None
-43579.0852515
4402.68969743

power_1
None
280.622770886
1.93639855513

[2 rows x 4 columns]

``````
``````

In [12]:

import matplotlib.pyplot as plt
%matplotlib inline

``````
``````

In [13]:

plt.plot(poly1_data['power_1'],poly1_data['price'],'.',
poly1_data['power_1'], model1.predict(poly1_data),'-')

``````
``````

Out[13]:

[<matplotlib.lines.Line2D at 0x133c5d6d0>,
<matplotlib.lines.Line2D at 0x133c5d790>]

``````

Let's unpack that plt.plot() command. The first pair of SArrays we passed are the 1st power of sqft and the actual price we then ask it to print these as dots '.'. The next pair we pass is the 1st power of sqft and the predicted values from the linear model. We ask these to be plotted as a line '-'.

We can see, not surprisingly, that the predicted values all fall on a line, specifically the one with slope 280 and intercept -43579. What if we wanted to plot a second degree polynomial?

``````

In [14]:

poly2_data = polynomial_sframe(sales['sqft_living'], 2)
my_features = poly2_data.column_names() # get the name of the features
poly2_data['price'] = sales['price'] # add price to the data since it's the target
model2 = graphlab.linear_regression.create(poly2_data, target = 'price', features = my_features, validation_set = None)

``````
``````

Linear regression:

--------------------------------------------------------

Number of examples          : 21613

Number of features          : 2

Number of unpacked features : 2

Number of coefficients    : 3

Starting Newton Method

--------------------------------------------------------

+-----------+----------+--------------+--------------------+---------------+

| Iteration | Passes   | Elapsed Time | Training-max_error | Training-rmse |

+-----------+----------+--------------+--------------------+---------------+

| 1         | 2        | 0.039490     | 5913020.984255     | 250948.368758 |

+-----------+----------+--------------+--------------------+---------------+

SUCCESS: Optimal solution found.

``````
``````

In [15]:

model2.get("coefficients")

``````
``````

Out[15]:

name
index
value
stderr

(intercept)
None
199222.496445
7058.00483552

power_1
None
67.9940640677
5.28787201316

power_2
None
0.0385812312789
0.000898246547032

[3 rows x 4 columns]

``````
``````

In [16]:

plt.plot(poly2_data['power_1'],poly2_data['price'],'.',
poly2_data['power_1'], model2.predict(poly2_data),'-')

``````
``````

Out[16]:

[<matplotlib.lines.Line2D at 0x122b5a490>,
<matplotlib.lines.Line2D at 0x122b5a550>]

``````

The resulting model looks like half a parabola. Try on your own to see what the cubic looks like:

``````

In [18]:

poly3_data = polynomial_sframe(sales['sqft_living'], 3)
my_features = poly3_data.column_names() # get the name of the features
poly3_data['price'] = sales['price'] # add price to the data since it's the target
model3 = graphlab.linear_regression.create(poly3_data, target = 'price', features = my_features, validation_set = None)

``````
``````

Linear regression:

--------------------------------------------------------

Number of examples          : 21613

Number of features          : 3

Number of unpacked features : 3

Number of coefficients    : 4

Starting Newton Method

--------------------------------------------------------

+-----------+----------+--------------+--------------------+---------------+

| Iteration | Passes   | Elapsed Time | Training-max_error | Training-rmse |

+-----------+----------+--------------+--------------------+---------------+

| 1         | 2        | 0.064835     | 3261066.736007     | 249261.286346 |

+-----------+----------+--------------+--------------------+---------------+

SUCCESS: Optimal solution found.

``````
``````

In [19]:

plt.plot(poly3_data['power_1'],poly3_data['price'],'.',
poly3_data['power_1'], model3.predict(poly3_data),'-')

``````
``````

Out[19]:

[<matplotlib.lines.Line2D at 0x121fa0390>,
<matplotlib.lines.Line2D at 0x121fa0450>]

``````

Now try a 15th degree polynomial:

``````

In [22]:

poly15_data = polynomial_sframe(sales['sqft_living'], 15)
my_features = poly15_data.column_names() # get the name of the features
poly15_data['price'] = sales['price'] # add price to the data since it's the target
model15 = graphlab.linear_regression.create(poly15_data, target = 'price', features = my_features, validation_set = None)

``````
``````

Linear regression:

--------------------------------------------------------

Number of examples          : 21613

Number of features          : 15

Number of unpacked features : 15

Number of coefficients    : 16

Starting Newton Method

--------------------------------------------------------

+-----------+----------+--------------+--------------------+---------------+

| Iteration | Passes   | Elapsed Time | Training-max_error | Training-rmse |

+-----------+----------+--------------+--------------------+---------------+

| 1         | 2        | 0.030345     | 2662308.584343     | 245690.511190 |

+-----------+----------+--------------+--------------------+---------------+

SUCCESS: Optimal solution found.

``````
``````

In [23]:

plt.plot(poly15_data['power_1'],poly15_data['price'],'.',
poly15_data['power_1'], model15.predict(poly15_data),'-')

``````
``````

Out[23]:

[<matplotlib.lines.Line2D at 0x13455d050>,
<matplotlib.lines.Line2D at 0x13455d110>]

``````
``````

In [32]:

def fitAndPlot(data, degree):
poly_data = polynomial_sframe(data['sqft_living'], degree)
my_features = poly_data.column_names() # get the name of the features
poly_data['price'] = data['price'] # add price to the data since it's the target
model = graphlab.linear_regression.create(poly_data, target = 'price', features = my_features, validation_set = None)
plt.plot(poly_data['power_1'],poly_data['price'],'.',
poly_data['power_1'], model.predict(poly_data),'-')
model.get("coefficients").print_rows(num_rows = 16)

``````

What do you think of the 15th degree polynomial? Do you think this is appropriate? If we were to change the data do you think you'd get pretty much the same curve? Let's take a look.

``````

In [33]:

fitAndPlot(sales, 15)

``````
``````

Linear regression:

--------------------------------------------------------

Number of examples          : 21613

Number of features          : 15

Number of unpacked features : 15

Number of coefficients    : 16

Starting Newton Method

--------------------------------------------------------

+-----------+----------+--------------+--------------------+---------------+

| Iteration | Passes   | Elapsed Time | Training-max_error | Training-rmse |

+-----------+----------+--------------+--------------------+---------------+

| 1         | 2        | 0.028724     | 2662308.584343     | 245690.511190 |

+-----------+----------+--------------+--------------------+---------------+

SUCCESS: Optimal solution found.

+-------------+-------+--------------------+-------------------+
|     name    | index |       value        |       stderr      |
+-------------+-------+--------------------+-------------------+
| (intercept) |  None |   73619.7521173    |        nan        |
|   power_1   |  None |   410.287462519    |        nan        |
|   power_2   |  None |   -0.23045071441   |        nan        |
|   power_3   |  None | 7.58840542352e-05  |        nan        |
|   power_4   |  None | -5.65701802391e-09 |        nan        |
|   power_5   |  None | -4.57028130952e-13 |        nan        |
|   power_6   |  None | 2.66360206687e-17  |        nan        |
|   power_7   |  None | 3.38584769195e-21  |        nan        |
|   power_8   |  None | 1.14723104126e-25  |        nan        |
|   power_9   |  None | -4.65293586384e-30 |        nan        |
|   power_10  |  None | -8.68796201998e-34 | 8.11474166966e-30 |
|   power_11  |  None | -6.30994295708e-38 |        nan        |
|   power_12  |  None | -2.70390383736e-42 |        nan        |
|   power_13  |  None | -1.21241980707e-47 |        nan        |
|   power_14  |  None | 1.11397452814e-50  |        nan        |
|   power_15  |  None |  1.3988169079e-54  |        nan        |
+-------------+-------+--------------------+-------------------+
[16 rows x 4 columns]

``````

# Changing the data and re-learning

We're going to split the sales data into four subsets of roughly equal size. Then you will estimate a 15th degree polynomial model on all four subsets of the data. Print the coefficients (you should use .print_rows(num_rows = 16) to view all of them) and plot the resulting fit (as we did above). The quiz will ask you some questions about these results.

To split the sales data into four subsets, we perform the following steps:

• First split sales into 2 subsets with `.random_split(0.5, seed=0)`.
• Next split the resulting subsets into 2 more subsets each. Use `.random_split(0.5, seed=0)`.

We set `seed=0` in these steps so that different users get consistent results. You should end up with 4 subsets (`set_1`, `set_2`, `set_3`, `set_4`) of approximately equal size.

``````

In [25]:

sub1, sub2 = sales.random_split(0.5, seed=0)
set_1, set_2 = sub1.random_split(0.5, seed=0)
set_3, set_4 = sub2.random_split(0.5, seed=0)

``````

Fit a 15th degree polynomial on set_1, set_2, set_3, and set_4 using sqft_living to predict prices. Print the coefficients and make a plot of the resulting model.

``````

In [34]:

fitAndPlot(set_1, 15)

``````
``````

Linear regression:

--------------------------------------------------------

Number of examples          : 5404

Number of features          : 15

Number of unpacked features : 15

Number of coefficients    : 16

Starting Newton Method

--------------------------------------------------------

+-----------+----------+--------------+--------------------+---------------+

| Iteration | Passes   | Elapsed Time | Training-max_error | Training-rmse |

+-----------+----------+--------------+--------------------+---------------+

| 1         | 2        | 0.047649     | 2195218.932303     | 248858.822200 |

+-----------+----------+--------------+--------------------+---------------+

SUCCESS: Optimal solution found.

+-------------+-------+--------------------+-------------------+
|     name    | index |       value        |       stderr      |
+-------------+-------+--------------------+-------------------+
| (intercept) |  None |   223312.750249    |   695899.624593   |
|   power_1   |  None |   118.086127587    |   2869.87932608   |
|   power_2   |  None |  -0.0473482011343  |   4.91122309897   |
|   power_3   |  None | 3.25310342469e-05  |  0.0046352535127  |
|   power_4   |  None | -3.3237215256e-09  | 2.71778579846e-06 |
|   power_5   |  None | -9.75830457858e-14 | 1.06405045948e-09 |
|   power_6   |  None | 1.15440303428e-17  | 2.93930601145e-13 |
|   power_7   |  None |  1.0514586943e-21  | 5.95124180195e-17 |
|   power_8   |  None | 3.46049616304e-26  |  8.9224296359e-21 |
|   power_9   |  None | -1.09654454065e-30 | 1.00089355409e-24 |
|   power_10  |  None | -2.42031812174e-34 | 8.78242615955e-29 |
|   power_11  |  None | -1.99601206791e-38 | 4.22782042938e-33 |
|   power_12  |  None | -1.07709903794e-42 |        nan        |
|   power_13  |  None | -2.72862817692e-47 |        nan        |
|   power_14  |  None | 2.44782693193e-51  | 7.47423189321e-46 |
|   power_15  |  None | 5.01975232664e-55  | 2.65144504924e-50 |
+-------------+-------+--------------------+-------------------+
[16 rows x 4 columns]

``````
``````

In [35]:

fitAndPlot(set_2, 15)

``````
``````

Linear regression:

--------------------------------------------------------

Number of examples          : 5398

Number of features          : 15

Number of unpacked features : 15

Number of coefficients    : 16

Starting Newton Method

--------------------------------------------------------

+-----------+----------+--------------+--------------------+---------------+

| Iteration | Passes   | Elapsed Time | Training-max_error | Training-rmse |

+-----------+----------+--------------+--------------------+---------------+

| 1         | 2        | 0.071831     | 2069212.978548     | 234840.067186 |

+-----------+----------+--------------+--------------------+---------------+

SUCCESS: Optimal solution found.

+-------------+-------+--------------------+-------------------+
|     name    | index |       value        |       stderr      |
+-------------+-------+--------------------+-------------------+
| (intercept) |  None |   89836.5077345    |        nan        |
|   power_1   |  None |   319.806946761    |        nan        |
|   power_2   |  None |   -0.10331539704   |        nan        |
|   power_3   |  None | 1.06682476065e-05  |        nan        |
|   power_4   |  None | 5.75577097724e-09  |        nan        |
|   power_5   |  None | -2.54663464776e-13 |        nan        |
|   power_6   |  None | -1.09641345064e-16 |        nan        |
|   power_7   |  None | -6.36458441552e-21 |        nan        |
|   power_8   |  None | 5.52560416854e-25  |        nan        |
|   power_9   |  None | 1.35082038962e-28  |        nan        |
|   power_10  |  None |  1.1840818824e-32  | 1.44802370273e-27 |
|   power_11  |  None | 1.98348000546e-37  |        nan        |
|   power_12  |  None | -9.92533590235e-41 |        nan        |
|   power_13  |  None | -1.60834847034e-44 |        nan        |
|   power_14  |  None | -9.12006024345e-49 |        nan        |
|   power_15  |  None | 1.68636658316e-52  | 4.15727809829e-48 |
+-------------+-------+--------------------+-------------------+
[16 rows x 4 columns]

``````
``````

In [36]:

fitAndPlot(set_3, 15)

``````
``````

Linear regression:

--------------------------------------------------------

Number of examples          : 5409

Number of features          : 15

Number of unpacked features : 15

Number of coefficients    : 16

Starting Newton Method

--------------------------------------------------------

+-----------+----------+--------------+--------------------+---------------+

| Iteration | Passes   | Elapsed Time | Training-max_error | Training-rmse |

+-----------+----------+--------------+--------------------+---------------+

| 1         | 2        | 0.047415     | 2269769.506523     | 251460.072754 |

+-----------+----------+--------------+--------------------+---------------+

SUCCESS: Optimal solution found.

+-------------+-------+--------------------+-------------------+
|     name    | index |       value        |       stderr      |
+-------------+-------+--------------------+-------------------+
| (intercept) |  None |   87317.9795608    |    1495007.709    |
|   power_1   |  None |    356.30491103    |   7602.19096579   |
|   power_2   |  None |  -0.164817442795   |   16.3391796762   |
|   power_3   |  None | 4.40424992642e-05  |  0.0196519133281  |
|   power_4   |  None | 6.48234877013e-10  | 1.47563784458e-05 |
|   power_5   |  None | -6.7525322657e-13  | 7.29073319682e-09 |
|   power_6   |  None | -3.36842592813e-17 | 2.42421128657e-12 |
|   power_7   |  None | 3.60999704343e-21  | 5.42287417817e-16 |
|   power_8   |  None | 6.46999725602e-25  | 7.96856377027e-20 |
|   power_9   |  None | 4.23639388764e-29  | 7.35880336516e-24 |
|   power_10  |  None | -3.6214942413e-34  | 4.05155780711e-28 |
|   power_11  |  None | -4.27119527344e-37 |        nan        |
|   power_12  |  None | -5.61445971796e-41 |        nan        |
|   power_13  |  None | -3.87452772905e-45 | 1.97399637393e-40 |
|   power_14  |  None |  4.6943035873e-50  | 2.02024283133e-44 |
|   power_15  |  None |  6.390458861e-53   | 4.89875784491e-49 |
+-------------+-------+--------------------+-------------------+
[16 rows x 4 columns]

``````
``````

In [37]:

fitAndPlot(set_4, 15)

``````
``````

Linear regression:

--------------------------------------------------------

Number of examples          : 5402

Number of features          : 15

Number of unpacked features : 15

Number of coefficients    : 16

Starting Newton Method

--------------------------------------------------------

+-----------+----------+--------------+--------------------+---------------+

| Iteration | Passes   | Elapsed Time | Training-max_error | Training-rmse |

+-----------+----------+--------------+--------------------+---------------+

| 1         | 2        | 0.046024     | 2314893.173821     | 244563.136754 |

+-----------+----------+--------------+--------------------+---------------+

SUCCESS: Optimal solution found.

+-------------+-------+--------------------+-------------------+
|     name    | index |       value        |       stderr      |
+-------------+-------+--------------------+-------------------+
| (intercept) |  None |   259020.879441    |   1307073.02598   |
|   power_1   |  None |   -31.7277161776   |   7952.15483588   |
|   power_2   |  None |   0.109702769596   |   19.8195176127   |
|   power_3   |  None | -1.58383847271e-05 |  0.0262937684635  |
|   power_4   |  None | -4.47660623782e-09 | 1.96298052368e-05 |
|   power_5   |  None | 1.13976573451e-12  | 5.99259928644e-09 |
|   power_6   |  None | 1.97669120566e-16  |        nan        |
|   power_7   |  None | -6.15783677673e-21 |        nan        |
|   power_8   |  None | -4.88012304265e-24 |        nan        |
|   power_9   |  None | -6.62186781127e-28 |        nan        |
|   power_10  |  None | -2.7063158353e-32  |        nan        |
|   power_11  |  None | 6.72370411646e-36  | 6.52111400502e-31 |
|   power_12  |  None | 1.74115646321e-39  | 8.54656664846e-35 |
|   power_13  |  None | 2.09188375702e-43  | 1.05182160121e-38 |
|   power_14  |  None |  4.7801556522e-48  | 7.22087430167e-43 |
|   power_15  |  None | -4.74535333035e-51 | 1.92750762068e-47 |
+-------------+-------+--------------------+-------------------+
[16 rows x 4 columns]

``````

Quiz Question: Is the sign (positive or negative) for power_15 the same in all four models?

Quiz Question: (True/False) the plotted fitted lines look the same in all four plots

# Selecting a Polynomial Degree

Whenever we have a "magic" parameter like the degree of the polynomial there is one well-known way to select these parameters: validation set. (We will explore another approach in week 4).

We split the sales dataset 3-way into training set, test set, and validation set as follows:

• Split our sales data into 2 sets: `training_and_validation` and `testing`. Use `random_split(0.9, seed=1)`.
• Further split our training data into two sets: `training` and `validation`. Use `random_split(0.5, seed=1)`.

Again, we set `seed=1` to obtain consistent results for different users.

``````

In [39]:

training_and_validation, testing = sales.random_split(0.9, seed=1)
training, validation = training_and_validation.random_split(0.5, seed=1)

``````

Next you should write a loop that does the following:

• For degree in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] (to get this in python type range(1, 15+1))
• Build an SFrame of polynomial data of train_data['sqft_living'] at the current degree
• hint: my_features = poly_data.column_names() gives you a list e.g. ['power_1', 'power_2', 'power_3'] which you might find useful for graphlab.linear_regression.create( features = my_features)
• Add train_data['price'] to the polynomial SFrame
• Learn a polynomial regression model to sqft vs price with that degree on TRAIN data
• Compute the RSS on VALIDATION data (here you will want to use .predict()) for that degree and you will need to make a polynmial SFrame using validation data.
• Report which degree had the lowest RSS on validation data (remember python indexes from 0)

(Note you can turn off the print out of linear_regression.create() with verbose = False)

``````

In [55]:

def fitAndValidate(training, validation, degree):
poly_train = polynomial_sframe(training['sqft_living'], degree)
my_features = poly_train.column_names() # get the name of the features
poly_train['price'] = training['price'] # add price to the data since it's the target
model = graphlab.linear_regression.create(poly_train, target = 'price', verbose=False,
features = my_features, validation_set = None)
poly_validation = polynomial_sframe(validation['sqft_living'], degree)
predictions = model.predict(poly_validation)
errors = predictions - validation['price']

``````
``````

In [56]:

for degree in range(1, 16):
model, modelRSS = fitAndValidate(training, validation, degree)

``````
``````

6

``````

Quiz Question: Which degree (1, 2, …, 15) had the lowest RSS on Validation data?

Now that you have chosen the degree of your polynomial using validation data, compute the RSS of this model on TEST data. Report the RSS on your quiz.

``````

In [57]:

model, RSS = fitAndValidate(training, validation, 6)

``````

Quiz Question: what is the RSS on TEST data for the model with the degree selected from Validation data?

``````

In [64]:

poly_test = polynomial_sframe(testing['sqft_living'], degree)
poly_test['price'] = testing['price']
model.evaluate(poly_test)

``````
``````

Out[64]:

{'max_error': 1850506.8665737142, 'rmse': 237952.2262921197}

``````
``````

In [65]:

errors = model.predict(poly_test) - testing['price']

``````
``````

1.25529337848e+14

``````
``````

In [ ]:

``````