Question
Nancy Pollock,Lawrence of Arabia,2.5,Gravity,3.5,The Godfather,3.0,Prometheus,3.5,For a Few Dollars More,2.5,The Guns of Navarone,3.0 Jack Holmes,Lawrence of Arabia,3.0,Gravity,3.5,The Godfather,1.5,Prometheus,5.0,The Guns of Navarone,3.0,For a Few Dollars More,3.5 Mary
Nancy Pollock,Lawrence of Arabia,2.5,Gravity,3.5,The Godfather,3.0,Prometheus,3.5,For a Few Dollars More,2.5,The Guns of Navarone,3.0 Jack Holmes,Lawrence of Arabia,3.0,Gravity,3.5,The Godfather,1.5,Prometheus,5.0,The Guns of Navarone,3.0,For a Few Dollars More,3.5 Mary Doyle,Lawrence of Arabia,2.5,Gravity,3.0,Prometheus,3.5,The Guns of Navarone,4.0 Doug Redpath,Gravity,3.5,The Godfather,3.0,The Guns of Navarone,4.5,Prometheus,4.0,For a Few Dollars More,2.5 Jill Brown,Lawrence of Arabia,3.0,Gravity,4.0,The Godfather,2.0,Prometheus,3.0,The Guns of Navarone,3.0,For a Few Dollars More,2.0 Trevor Chappell,Lawrence of Arabia,3.0,Gravity,4.0,The Guns of Navarone,3.0,Prometheus,5.0,For a Few Dollars More,3.5 Peter,Gravity,4.5,For a Few Dollars More,1.0,Prometheus,4.0
The file contains names of reviewers and their reviews of different movies in the comma separated format. The first string is the name of the reviewer followed by a name of a movie and its rating. You are required to write a Python program that computes a similarity score between any two reviewers using Euclidean distances. An example data from the movie_reviews.txt file is given below:
Trevor Chappells reviews are:
'Lawrence of Arabia': 3.0,
'Gravity': 4.0,
'The Guns of Navarone': 3.0,
'Prometheus': 5.0,
'For a Few Dollars More': 3.5
Peters reviews are:
'Gravity':4.5,
'For a Few Dollars More':1.0,
'Prometheus':4.0
The Euclidean distance between Peter and Trevor Chappell is computed as follows:
1) Only consider the movies that both have reviewed.
2) Take the difference between corresponding reviews.
3) Sum the square of the differences
4) The square root of the sum of differences is the Euclidean score. The shorter the distance the closer the two reviewers.
For our example, this would be: (4.0 4.5)2 + (3.5 1.0)2 + (5.0 4.0)2 = 0.25 + 6.25 + 1 = 7.5
Euclidean distance is Square Root of 7.5 = 2.7386
Your program should provide the following:
1) Ability to read in a user provided filename which contains movie reviews in the comma separated format similar to the given file movie_reviews.txt
2) Functionality to compute the similarity between two reviewers provided by the user
3) Functionality to compute the similarity between one user provided reviewer and all other reviewers in the database
A sample run for the two required functionalities is given below (user inputs are in red):
Give the name of the movie reviews file: movie_reviews.txt
#if the name not correct , return "please enter the correct name"
What do you want to do? Input 1 for similarity between two reviewers, or Input 2 for similarity between one reviewer and all others in the database or 3 to quit: 1
Provide Reviewer1 name: Peter
Provide Reviewer2 name: Trevor Chappell
The similarity score between Peter and Trevor Chappell is: 2.7386
What do you want to do? Input 1 for similarity between two reviewers, or Input 2 for similarity between one reviewer and all others in the database or 3 to quit: 2
Provide Reviewer name: Peter
The Similarity Scores are:
Peter Nancy Pollock 1.87
Peter Jill Brown 1.50
Peter Jack Holmes 2.87
Peter Trevor Chappell 2.74
Peter Mary Doyle 1.58
Peter Doug Redpath 1.80
What do you want to do? Input 1 for similarity between two reviewers, or Input 2 for similarity between one reviewer and all others in the database or 3 to quit: 3
Goodbye!
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