Question: The question I have is how to write the code for the euclidian distance using the #user ratings. I don't know how to set it
The question I have is how to write the code for the euclidian distance using the #user ratings. I don't know how to set it up. I have kept the class similarity at the top b/c they want it to be used to calculate it.
import math from operator import itemgetter
# definie class similarity class similarity: # Class instantiation def __init__ (self, ratingP, ratingQ): self.ratings1 = ratingP self.ratings2 = ratingQ
# user ratings songData3 = {"Angelica": {"Blues Traveler": 3.5, "Broken Bells": 2.0, "Norah Jones": 4.5, "Phoenix": 5.0, "Slightly Stoopid": 1.5, "The Strokes": 2.5, "Vampire Weekend": 2.0}, "Bill":{"Blues Traveler": 2.0, "Broken Bells": 3.5, "Deadmau5": 4.0, "Phoenix": 2.0, "Slightly Stoopid": 3.5, "Vampire Weekend": 3.0}, "Chan": {"Blues Traveler": 5.0, "Broken Bells": 1.0, "Deadmau5": 1.0, "Norah Jones": 3.0, "Phoenix": 5, "Slightly Stoopid": 1.0}, "Dan": {"Blues Traveler": 3.0, "Broken Bells": 4.0, "Deadmau5": 4.5, "Phoenix": 3.0, "Slightly Stoopid": 4.5, "The Strokes": 4.0, "Vampire Weekend": 2.0}, "Hailey": {"Broken Bells": 4.0, "Deadmau5": 1.0, "Norah Jones": 4.0, "The Strokes": 4.0, "Vampire Weekend": 1.0}, "Jordyn": {"Broken Bells": 4.5, "Deadmau5": 4.0, "Norah Jones": 5.0, "Phoenix": 5.0, "Slightly Stoopid": 4.5, "The Strokes": 4.0, "Vampire Weekend": 4.0}, "Sam": {"Blues Traveler": 5.0, "Broken Bells": 2.0, "Norah Jones": 3.0, "Phoenix": 5.0, "Slightly Stoopid": 4.0, "The Strokes": 5.0}, "Veronica": {"Blues Traveler": 3.0, "Norah Jones": 5.0, "Phoenix": 4.0, "Slightly Stoopid": 2.5, "The Strokes": 3.0} }
# for whom are we making recommendations? userX = "Hailey" userXRatings = songData3[userX]
# find the euclidean distance between userX's ratings, and each of the other user's ratings. # use a for loop to get at the other users and their ratings - DO NOT hard code. # use the similarity class to calculate the euclidean distance between user ratings. # assign list of (user, distance) tuples to variable userDistances. # Example: [('Jordyn', 4.39), ('Chan', 3.16), ('Veronica', 1.41), ('Bill', 3.64)] userDistances = [ ]
# <<<<< (1) YOUR CODE HERE >>>>>
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
