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]
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:
Code: see image.