Question: Part 6 : Test Score We will now calculate the testing r - squared score for our model by repeating the steps from Part 5
Part : Test Score
We will now calculate the testing rsquared score for our model by repeating the steps from Part but using the test set
rather than the training set.
Create a markdown cell with a level header that reads "Part : Test Score".
In the same cell, add unformatted text explaining that in this section, we will be calculating the test rsquared score, and
that we will start by calculating estimated response values for the test set.
Use the variables beta and beta as well as the list xtest to calculate the estimated response values for the test
set. Store the results in a list named predytest. You can accomplish this task using either a loop or a list
comprehension. This cell should not produce any output.
Create a markdown cell explaining that we will now calculate the residuals for the test set.
Use the values stored in ytest and predytest to calculate the residuals for the test set. Store the results in a list
named errorytest. You can accomplish this task using either a loop or a list comprehension. This cell should not
produce any output.
Before continuing on with our calculation of the rsquared score, we will display the true values, the predicted values,
and the residual for each of the first observations in the test set.
Create a markdown cell explaining that we will be displaying the values mentioned above.
Use a code cell to print the first values of each of the lists ytest, predytest, and errorytest. The output
should be formatted in the same way as what was requested for the training set in Part
Create a markdown cell explaining that we will now calculate the sum of squared errors score for the test set.
Use the values stored in the list errorytest to calculate the testing sum of squared errors score, storing the result in
a variable name ssetest. Display the result with text output as shown below, rounding the displayed value to
decimal places.
Test SSE xxxx
Before calculating the test rsquared score, we must first calculate the value for the test set. We calculated this for the
training set in Part but have not done so for the test set.
Create a markdown cell explaining that we will now calculate the value of on the test set, and will then use that and the
test sum of squared errors to calculate the test rsquared score.
Use the formula from Part to calculate the value for the test set, storing the results in a variable named Syytest.
Then calculate the test rsquared score, storing the result in a variable named rtest. Display the result with text
output as shown below, rounding the displayed value to decimal places.
Test rSquared xxxx
Create a markdown cell explaining that we will now create a plot to visualize the errors for the observations in the test set.
Copy the code below without the indentation into a code cell and then execute that cell.
pltfigurefigsize
pltscatterxtest, ytest, c'skyblue', edgecolork
pltplotbeta beta beta beta
c'crimson', lw
for i in rangentest:
pltplotxtesti xtestipredytesti ytesti
c'coral', zorder
pltshow
Each vertical line shown in this plot represents th
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
