Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Here's my code and I'm getting an error: length=[22.7, 22.4, 25.8, 21.3, 20.1, 22.1, 21.1, 25.3, 26.9, 26.9, 23.0, 23.8, 26.2, 20.4, 23.0, 21.9, 23.5,
Problem 6: Calculating Sum of Squared Errors Suppose that a biologist is studying the relationship between the length and weight of yellow-bellied marmots. Based on prior work, she believes that the length and weight of adult marmots can be approximately modeled by a relationship of the following form: weight = 0.6* length - 5.2 To test this model, the biologist collects a sample of 20 adult marmots. The lengths and weights of the marmots are as follows: length = [22.7, 22.4, 25.8, 21.3, 20.1, 22.1, 21.1, 25.3, 26.9, 26.9, 23.0, 23.8, 26.2, 20.4, 23.0, 21.9, 23.5, 27.8, 25.3, 25.9] weight = [9.2, 8.8, 10.7, 8.3, 6.2, 8.6, 7.2, 11.2, 10.5, 11.3, 9.6, 9.9, 10.9, 5.9, 9.5, 9.1, 9.7, 11.6, 10.2, 10.5] Create these lists, as the appear here. You do not need to print anything in this cell. Create a list named pred_weight containing the predicted weight for each marmot, according to the biologist's model. You should begin by creating pred_weight as an empty list. Then loop over the elements of length. Each iteration of the loop should calculate a new predicted weight using the formula provided above, and rounded to 2 decimal places. The round value for each predicted weight should be appended to the list pred_weight. Print pred_weight. The biologist wishes to score her model using the sum of squared errors (SSE) metric. This metric is calculated as follows: 1. For each observation, calculate the difference between the true weight and the predicted weight. 2. Square this difference. 3. Sum the squared differences over all observations Use a for loop to calculate the model's SSE score for this sample of marmots. There are multiple ways to perform this task, but for the sake of efficiency, I would like for you to do it without creating any new lists and using only one loop. Print the value of SSE, rounded to four decimal places. Note that the value stored in SSE should not be rounded, only the value displayed.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started