Problem Definition

Lets say we have two users, User P and User Q, and they have rated 6 different cell phone brands on a scale of 1 to 10.

Item Ratings of User P Ratings of User Q
Apple p_0=10 q_0=5
Samsung p_1=5 q_1=10
Nokia p_2=7 q_2=4
Motorola p_3= 9 q_3=1
LG p_4=3 q_4=3
Sony p_5=1 q_5=6

In Python, we can depict these ratings as two lists:

UserPRatings = [10, 5, 7, 9, 3, 1]
UserQRatings = [5, 10, 4, 1, 3, 6]

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 lists 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 minkowskiwhich takes a single parameter r, and returns the MinkowkiDistance between the two lists (that the Class object isinstantiated with)

(2)Code up the Class method called pearson which takes no parameters, and returns the Pearson Correlation between the two lists (that the Class object isinstantiated with)

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

  • Manhattan Distance (Minkowski r=1),
  • Euclidean Distance (Minkowski r=2),
  • MinkowskiDistance (Minkowski r=3),
  • Pearson Correlation

Framework for coding:

Code: see image.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.