Two Dimensional Arrays

Lab #2

 

An interesting Machine Learning Artificial Intelligence application is building “Recommender” Systems.  An example of a recommender system is a system that will tell you whether or not you will like the NEW MOVIE that was just released.  How can a system do this?

 

A collaborative recommender system constantly asks users to say whether they like or dislike movies.  It builds up a database of information that looks as follows:  (This is only for 5 movies and 6 people, but it could be much larger.  An entry of 10 means likes a lot and 1 means dislikes). 

 

User

Movie 1

Movie 2

Movie 3

Movie 4

NEW MOVIE

John

10

3

8

2

9

Tim

8

2

1

1

7

Mary

7

2

8

3

7

Sally

7

2

6

1

5

Emile

2

8

8

9

9

Bea

1

9

2

1

2

 

If you want the recommender system to tell you if you will like NEW MOVIE, the system will ask you whether or not you like Movie 1, Movie 2, Movie 3 and Movie 4.  It then finds the user most similar to you (in AI language this is called your nearest neighbor!).  If your nearest neighbor liked NEW MOVIE, it will be recommended to you, otherwise you will be told NOT to waste your time with it.

 

Write a program that declares a two–dimensional array and fills it with the “movie data base” above.  It is a 6 by 5 two-dim array because it is storing information for 6 people, with 5 movies each.

 

When your program runs, it will ask the user to enter a score for the Movie 1, Movie 2, Movie 3, Movie 4, and will store those values in a one dimensional array.  It then finds the user’s nearest neighbor and uses that line of the two dimensional array to output a message giving you a score for New Movie.

 

To find the nearest neighbor, you must compute the distance between the array (or vector) that holds the user’s numbers and each line in the two dimensional array.  You can use the standard Euclidean  distance (same as distance between two points, except in higher dimensions).  For two  arrays, p and q of length n, it would be:

 

 

 

EXTRA CREDIT:  Instead of checking the nearest neighbor, have a vote between the three closest neighbors on whether the new user will like the NEW MOVIE or not. You can simply vote by taking the average rating of the three closest neighbors.

 

Something to think about:  Instead of simply taking the average of the three nearest neighbors, take the weighted average.  Weigh the vote by “how close” that neighbor is.

 

Something else to think about:  Each person rates movies differently.  Perhaps the highest rating that you ever give a movie is a 6; maybe the lowest rating that I ever give is a 5.  So if I give a movie a 5 it means that I really don’t like it, if you give it a 5 it means that you really like it!