Question
2.12 Python Lab: Comparing voting records using dot-product In this lab, we will represent a US senators voting record (voting_record.txt) as a vector over R,
2.12 Python Lab: Comparing voting records using dot-product In this lab, we will represent a US senators voting record (voting_record.txt) as a vector over R, and will use dot-products to compare voting records. For this lab, we will just use a list to represent a vector.
Task 2.12.5: Use these procedures to figure out which senator is most like Rhode Island legend Lincoln Chafee. Then use these procedures to see who disagrees most with Pennsylvanias Rick Santorum. Give their names.
Task 2.12.6: How similar are the voting records of the two senators from your favorite state?
Task 2.12.7: Write a procedure find_average_similarity(sen, sen set, voting dict) that, given the name sen of a senator, compares that senators voting record to the voting records of all senators whose names are in sen set, computing a dot-product for each, and then returns the average dot-product. Use your procedure to compute which senator has the greatest average similarity with the set of Democrats (you can extract this set from the input file).
Task 2.12.8: Write a procedure find_average_record(sen set, voting dict) that, given a set of names of senators, finds the average voting record. That is, perform vector addition on the lists representing their voting records, and then divide the sum by the number of vectors. The result should be a vector.
Task 2.12.9: Write a procedure bitter_rivals(voting_dict) to find which two senators disagree the most.
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