Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 I came across a problem and I am stuck on it
I was given two files one with a person name and their rating which I put into a dictionary and then one with the author's names and their books they've written which were also put into dictionaries.

I was then asked to create an algorithm based on this.

A program can calculate how similar two users are by treating each of their ratings as a vector and calculating the dot
product of these two vectors. The dot product is simply the sum of the products of each of the corresponding elements.
For example, suppose we had 3 books in our database and User A rated them [5, 3, -5], User B rated them [1, 5, -
3], User C rated them [5, -3, 5], and User D rated them [1, 3, 0]. The similarity between Users A and B is calculated
as: (5 x 1) + (3 x 5) + (-5 x -3) = 5 + 15 + 15 = 35. The similarity between Users A and C is: (5 x 5) + (3 x -3) + (-5 x
5) = 25 - 9 - 25 = -9. The similarity between Users A and D is (5 x 1) + (3 x 3) + (-5 x 0) = 5 + 9 + 0 = 14. We see
that if both people like a book (rating it with a positive number) it increases their similarity and if both people dislike a
book (both giving it a negative number) it also increases their similarity.
Once you have calculated the pair-wise similarity between User A and every other user, you can then identify whose
ratings are most similar to User A’s. In this case, User B is most similar to User A, so we would recommend to
User A the top books from User B’s list that User A hasn't already read.

I am confused and stuck on how to create this
This is a homework problem, and so besides suggesting it might be better to post under Homework, will ask what you have done so far? We aren't going to do your homework for you, but are happy to assist once you get started, where you are stuck or where you are finding errors.

would suggest first defining your Users with their ratings, then form a loop that will find the similarity between A and each of the other Users.
I moved it to homework section
Start by solving the problem on pencil and paper. Don't think about dictionaries or python. Carefully document the steps taken to solve the problem without ambiguity. Is your solution general? If you changed the inputs does it still calculate the correct answer? If so you have just created an algorithm. Congrats!

Once you have the algorithm writing a program is mostly finding the right syntax and data structures. Programming is far simpler than coming up with the algorithm, and coming up with an algorithm is simpler if you aren't thinking about how you would write the program. There will come a time when you'll see multiple algorithms for solving a problem and programming language will affect which algorithm you choose to implement, but that time is in your future.
ndc85430 likes this post

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)