Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 4: Pollster errors Now that we can represent election results and polling data in Python, we can begin to implement Nate Silver's algorithm. A

Problem 4: Pollster errors Now that we can represent election results and polling data in Python, we can begin to implement Nate Silver's algorithm. A first step is to write a function that computes the rank (average error) of a pollster's predictions. Implement the function average_error, which computes the average error of pollster edges. In each state, the error of a predicted edge is the absolute value of the difference between the predicted edge and actual edge. The average error of a collection of pollster edges is the average of these individual errors. Hint: Not all pollsters conduct polls in every state. When computing an average error, be sure to divide by the number of states in which a pollster made a prediction, not by the total number of states. Next, use average_error to implement the function pollster_errors. Again, refer to the data type reference below for more information about parameter and return types. Once completed, pollster_errors provides a quantitative method for measuring the accuracy of a pollster, based on their past predictions.

- Python

- Following the following functions:

image text in transcribed

For the following test values:

image text in transcribed

# Problem 4: Pollster errors def average_error(state_edges_predicted, state_edges_actual): Given predicted state edges and actual state edges, returns the average error of the prediction. IT IT 11 - def pollster_errors (pollster_predictions, state_edges_actual): Given pollster predictions and actual state edges, retuns pollster errors. #TODO: Implement this function pass -def test_average_error(): state_edges_pred_1 = {'WA': 1.0, 'CA': -2.3, 'ID': -20.1} state_edges_act_1 = { 'WA': 2.1, 'CA': -1.4, 'ID': -19.1} assert average_error(state_edges_pred_1, state_edges_act_1) == 1.0 state_edges_pred_2 = {'WA': 1.0, 'CA': 2.0} state_edges_act_2 = { 'WA': 2.0, 'CA': 1.0} assert average_error(state_edges_pred_2, state_edges_act_2) == 1.0 state_edges_pred_3 = {'WA': 1.0, 'CA': 2.0} state_edges_act_3 = {'WA': 2.0, 'CA': 1.0, 'MA': 2.4, TOR': -3.9} assert average_error(state_edges_pred_3, state_edges_act_3) == 1.0 state_edges_pred_4 = { 'WA': 1.0} state_edges_act_4 = {'WA': 0.0} assert average_error(state_edges_pred_4, state_edges_act_4) == 1.0 - def test_pollster_errors(): predictions = { PPP': {'WA': 1.0, 'CA': -2.0, 'ID': -20.0}, 'ISPOP': {'WA': 2.0, 'ID': -19.0} } actual = {'WA': 2.0, 'CA': -1.0, 'ID': -19.0, 'OR': 2.2, 'DC': 0.1} assert pollster_errors (predictions, actual) == {'PPP': 1.0, 'ISPOP': 0.0}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions

Question

7. Senior management supports the career system.

Answered: 1 week ago