Starting from:

$25

Assignment 3 (Recommendation Systems) Python

Let’s say we have 5 users, User P and User Q, and they have rated 7 different cell phone brands on a scale of 1 to 10. Note that not all users have rated all cell phones.
c

UserPRatings = {'Motorola':8, 'LG':5, 'Sony':1, 'Apple':1, 'Samsung':5, 'Nokia':7}

UserQRatings = {'Apple':7, 'Samsung':1, 'Nokia':4, 'LG':4, 'Sony':6, 'Blackberry':3}

Requirement for this Assignment


You have been provided with a framework which defines a Class called similarity. It includes a class initialization method which takes two rating dictionaries ratingP and ratingQ as parameters. You must use the initialization method as-is with no changes.



Your task in this assignment is to extend the framework as follows:



(1) Code up the Class method called minkowski which takes a single parameter r (no additional parameters must be included in the method call), and returns the Minkowki Distance between the two dictionaries (that the Class object is instantiated with). Note: you must include a phone rating in the distance calculation only if the phone was rated by both users.



(2) Code up the Class method called pearson which takes no parameters (no additional parameters must be included in the method call), and returns the Pearson Correlation between the two dictionaries (that the Class object is instantiated with). Note: you must include a phone rating in the correlation calculation only if the phone was rated by both users.



(3) Create an object of class similarity. Initialize it with rating dictionaries UserPRatings and UserQRatings. Call the minkowski and pearson class methods to calculate the following measures between the two dictionaries:

o Manhattan Distance [Answer: 19.0]

o Euclidean Distance [Answer: 9.3274]

o Minkowski Distance (r=3) [Answer: 7.5654]

o Pearson Correlation [Answer: -0.7123]

















Framework for coding:




Assignment Submission


Some things to keep in mind as you code:

· Make your code readable – for instance, use meaningful variable names and comments.

· Make your code elegant – for instance, balance the number of variables you introduce – too many or too few make your code difficult to debug, read, and maintain.

· Make your output readable and user-friendly



Once you have written up the script, save it as follows. Submit the script by uploading your python script. Note: upload the actual script – DO NOT attach a screenshot of the script!

<FirstName<LastNameAssignment2.py.

[Example: HinaAroraAssignment2.py]



The submitted script will be run as-is for grading. Points will be deducted for scripts that:

· are difficult to read/follow

· don’t compile/run

· don’t have all the various pieces of code required

· have hard-code values instead of using variables

· have logical errors

· don’t result in the expected output

· don’t have user-friendly output

Hint


If you have coded up this assignment correctly, you should end up with Manhattan Distance of 19.0, Euclidean Distance of 9.3274, Minkowski Distance (r=3) of 7.5654, and Pearson Correlation of -0.7123.

More products