Two Dimensional Arrays An interesting Machine Learning Artificial Intelligence a
ID: 3628826 • Letter: T
Question
Two Dimensional Arrays
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
Movie1
Movie2
Movie3
Movie4
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 likedNEW 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 forNew 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 standardEuclidean distance (same as distance between two points, except in higher dimensions). For two arrays, p and q of length n, it would be:
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!
thanks
User
Movie1
Movie2
Movie3
Movie4
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
Explanation / Answer
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
#define PEOPLE 6
#define MOVIES 5
int main()
{
int database[PEOPLE][MOVIES]; //movie databse
string users[PEOPLE]; //user names
int i,j;
//getting input
for( i=0;i<PEOPLE;i++)
{
cout<<" Enter user "<<i+1<<" name: ";
cin>>users[i];
for( j = 0; j<MOVIES-1; j++)
{
cout<<" Enter movie "<<j+1<<" score: ";
cin>>database[i][j];
}
}
//finding new movie score as average of 4 movies
for( i=0;i<PEOPLE;i++)
{
database[i][MOVIES-1] = 0;
for( j=0;j<MOVIES-1;j++)
database[i][MOVIES-1] += database[i][j];
database[i][MOVIES-1] /= 4;
}
//displaying ouptut to console
cout<<" USER MOVIE1 MOVIE2 MOVIE3 MOVIE4 NEW MOVIE"<<endl;
for( i=0;i<PEOPLE;i++)
{
cout<<setw(10)<<users[i];
for( j=0;j<MOVIES;j++)
cout<<setw(9)<<database[i][j];
cout<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.