SlideShare a Scribd company logo
1 of 10
Lab 8
User-CF Recommender System – Part I
50 points
In this lab, we will focus on understanding the design of a user-
based collaborative filtering
recommender system. Then we will implement half that design
in this lab, and the other half in
the next lab.
System Description:
A user-based collaborative filtering (User-CF for short)
recommender works by making use of the
similarities between users in a system. To recommend items for
a specific user u, first User-CF finds the
n-most similar users to u. These are called the neighbors of u.
Then, the items that ratings that were given
by the neighbors of u for the different items are used to
generate recommendation scores for each item.
Finally, the m items with the highest recommendation scores are
recommended to u. The number of
neighbors n, and the number of items m can vary based on the
application in which the recommender is
used.
The overall flow of the user-based collaborative filtering
recommendation process can be summarized in
these steps:
1. Read movie information from file
2. Read user information from file
3. Generate movie recommendations for each user as follows.
For each user u:
a. Find u’s n most similar neighbors
i. Compute the Jaccard similarity between u and all other users
ii. Select the n users with the highest similarity values. Call
these n users the
neighbors of u.
b. Compute movie recommendation scores for u as follows.
i. For each movie, compute its recommendation score using the
rating information
for the neighbors of u.
ii. Select the m movies with the highest recommendation scores.
System Design:
1. The system will include a class named User to represent a
user. That class should include the user’s
ID, name, number of watched items, and a list containing the
IDs of the watched items. The class
should include a method for computing the number of similar
items between two users.
2. To allow for representing diverse items, the system will
include an abstract class named Item to
represent a generic item. This class will include the item’s ID,
name and description.
3. To represent movie items, the system will include a class
named Movie that inherits from the
abstract Item class. It will include the movie’s genre and
director.
4. The system will contain a generic Recommender class that
can be used to represent the
basic information and behavior of any recommender technique.
Specifically, it will
contain the list of users, list of items, and an abstract method
for generating
recommendations. This class is abstract.
5. The system will contain a more specific recommender class,
UserCFRecommender, that
inherits from the generic Recommender class. It will contain
methods that are specific
to this recommendation technique.
UML Diagram for the System Design:
Recall the meanings of the UML Symbols:
- Private
+ Public
# Protected
Lab Work:
1. You are provided with the java files containing all the class
names along with the class variables
and the method definitions.
2. You are required to implement the class methods that are
shown in Bold Red in the UML diagram
above.
3. The algorithm for each method is written, and commented,
inside each method in the java files.
4. Don’t forget to implement a constructor for each class to
initialize its data. Let your constructor
print a message indicating successful initialization of the object
data.
5. In your main method, create a UserCFRecommender object,
and use it to read the items and users
files. Then, print the user and item information to the console.
The users and items files are also
provided with the lab materials.
6. Run your main function and make sure that it is properly
reading the users and items information.
Lab Deliverables:
1. Zip all your code, along with a screen shot showing the
output obtained after you compiled and
run your code.
Movie.txt
1 , Toy story , Adventure Animation
2 , Jumanji , Adventure Fantasy
3 , Grumpy Old Men , Comedy Romance
4 , Waiting to Exhale , Comedy Drama Romance
5 , Father of the Bride Part II , Comedy
6 , Heat , Action Crime Thriller
7 , Sabrina , Comedy Romance
8 , Tom and Huck , Adventure Children
9 , Sudden Death , Action
10 , GoldenEye , Action Adventure Thriller
11 , The American President , Comedy Drama Romance
12 , Dracula: Dead and Loving It , Comedy Horror
13 , Balto , Animation Children
14 , Nixon , Drama
15 , Cutthroat Island , Action Adventure Romance
16 , Casino , Crime Drama
17 , Sense and Sensibility , Comedy Drama Romance
18 , Four Rooms , Comedy Drama Thriller
19 , Ace Ventura: When Nature Calls , Comedy
20 , Money Train , Action Comedy Crime Drama Thriller
item.java
abstract public class Item{ //data protected int ID;
protected String name; protected String description;
//methods public Item() { ID = -1; name =
""; description = ""; } public Item(int ID, String n,
String d) { this.ID = ID; this.name = n;
this.description = d; } public int get_ID() {return ID;}
public void set_ID(int i) {ID = i;} public String
get_name() {return name;} public void set_name(String i)
{name = i;} public String get_desciption() {return
description;} public void set_description(String i)
{description = i;}}
movie.java
public class Movie extends Item{ private String genre;
private String director; //methods public Movie(int id,
String n, String d, String g, String dir) { super(id, n,
d); genre = g; director = dir; } public void
set_genre(String g) {genre = g;} public String
get_genre(String g) {return genre;} public void
set_director(String g) {director = g;} public String
get_director(String g) {return director;}}
RecApp.java
public class RecApp{ public static void main(String[] args)
{ UserCFRecommender ucf = new
UserCFRecommender("", "movies.txt"); }}
Recommender.java
import java.util.Scanner;import java.io.*;public abstract class
Recommender{ protected User[] users = new User[10];
protected Item[] items = new Item[10];
//=========================
//========================= //reads items from a
file protected void read_items(String file_name) { /*
1. Open the file 2. Read file line by line
3. For each line, Extract ID, Name, & Genre
Create a Movie object Set Item ID,
Name & Genre Add the Movie object into the Items[]
items 6. Close the file */ try {
File f = new File(file_name);
Scanner s = new Scanner(f);
while(s.hasNext()) { String[]
vals = (s.nextLine()).split(" , "); for(int i=0;
i< vals.length; i++)
System.out.println(vals[i]);
System.out.println(); } }
catch (FileNotFoundException e) {} }
//=========================
//========================= protected void
read_users(String file_name) { /* 1. Open the
file 2. Read file line by line 3. For each line,
Extract ID, n_items For i = 0 to n_items
Extract the Movie IDs Create a
User Object Set User ID, n_items, and add all
items to that user. Add the User object into the
Users[] users 4. Close the file */ }
//=========================
//========================= public User[]
get_users() { return users; }
//=========================
//========================= public Item[]
get_items() { return items; }
//=========================
//========================= public abstract void
make_recommendations();}
UserCFRecommender.java
public class UserCFRecommender extends Recommender{
public UserCFRecommender() {} public
UserCFRecommender(String ufile, String ifile) {
read_items(ifile); read_users(ufile); }
//computes the Jaccard similarity between two users give
the //indices of both users in the Users[] users list. public
double compute_jaccard_sim(int u1_ind, int u2_ind) {
//1. get n_common_items: int n_common_items =
(users[u1_ind]).similarity(users[u2_ind]); //2. get
total_n_items using u1 n_items, u2 n_items & n_common_items
//3. compute Jaccard sim as
n_common_items/total_n_items return 0; } //finds
the nieghbors of a user given the user index in the //Users[]
users, and given the number of neighbors//returns neighbors
indices, and neighbors similarity values public void
find_user_neighbors(int u_ind, int n_neighbors, int[] n_ind,
double[] n_sim) { /* 1. Create an array
sim[] with size = n_users to save all similarity
values in 2. For each other user u compute
similarity between u_ind and u by calling the
compute_jaccard_sim method, and save the result in sim[u]
3. Scan sim[] and select the "n_neighbors" users with
the highest similarities. for i = 0 -> n_neighbors -1:
ind = -1 max = -1
for j = 0 -> n_users -1: if
sim[j]>max: max = sim[j]
ind = j save max & ind
into n_sim[i] and n_ind[i] set sim[ind] = -2
*/ } // public void
compute_recommendation_scores(int u_ind, int[] n_ind,
double[] n_sim, double[] scores) { } // public void
make_recommendations() {}}
users.txt
1 4 1 2 10 192 3 1 6 193 3 1 2 74 2 1 105 4 1 5 7 116 6 1 7 11
18 19 207 5 1 2 7 11 178 5 5 9 11 16 199 7 1 2 3 6 9 10 1910 5
1 2 10 18 1911 3 1 2 1612 7 1 2 3 5 10 11 1913 9 1 2 3 5 10 11
13 19 2014 5 2 6 16 17 1915 6 1 3 5 6 10 16
User.java
public class User{ //data private int ID; private String
name; private int n_items; private int[] items = new
int[100]; //methods public User() { ID = -1;
name = ""; n_items = 0; } public User(int
id, String n) { ID = id; name = n; n_items
= 0; } public void add_item(int i) {
items[n_items] = i; n_items++; } //computes
the number of common items between this and u. public int
similarity(User u) { int n = u.get_n_items();
int[] uitems = u.get_items(); int sim = 0;
for(int i=0; i<n; i++) for(int j=0; j<n_items;
j++) if(uitems[i] == items[j]){
sim++; break; }
return sim; } public int get_ID() {return ID;}
public int[] get_items() {return items;} public int
get_n_items() {return n_items;} public int set_ID(int i)
{ID = i;}}
Lab 8 User-CF Recommender System – Part I 50 points .docx

More Related Content

Similar to Lab 8 User-CF Recommender System – Part I 50 points .docx

Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfPRATIKSINHA7304
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0BG Java EE Course
 
Introduction to Recommender System
Introduction to Recommender SystemIntroduction to Recommender System
Introduction to Recommender SystemWQ Fan
 
Programming II hiding, and .pdf
 Programming II hiding, and .pdf Programming II hiding, and .pdf
Programming II hiding, and .pdfaludin007
 
Lecture01 object oriented-programming
Lecture01 object oriented-programmingLecture01 object oriented-programming
Lecture01 object oriented-programmingHariz Mustafa
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxDeepasCSE
 
Assignment #4 will be the construction of 2 new classes and a driver program/...
Assignment #4 will be the construction of 2 new classes and a driver program/...Assignment #4 will be the construction of 2 new classes and a driver program/...
Assignment #4 will be the construction of 2 new classes and a driver program/...hwbloom3
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android DevelopmentAly Abdelkareem
 

Similar to Lab 8 User-CF Recommender System – Part I 50 points .docx (20)

ClassesandObjects
ClassesandObjectsClassesandObjects
ClassesandObjects
 
ClassesandObjects
ClassesandObjectsClassesandObjects
ClassesandObjects
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Django Good Practices
Django Good PracticesDjango Good Practices
Django Good Practices
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
UNIONS.pptx
UNIONS.pptxUNIONS.pptx
UNIONS.pptx
 
Chap08
Chap08Chap08
Chap08
 
Introduction to Recommender System
Introduction to Recommender SystemIntroduction to Recommender System
Introduction to Recommender System
 
Programming II hiding, and .pdf
 Programming II hiding, and .pdf Programming II hiding, and .pdf
Programming II hiding, and .pdf
 
Lecture01 object oriented-programming
Lecture01 object oriented-programmingLecture01 object oriented-programming
Lecture01 object oriented-programming
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
 
Java oop concepts
Java oop conceptsJava oop concepts
Java oop concepts
 
Assignment #4 will be the construction of 2 new classes and a driver program/...
Assignment #4 will be the construction of 2 new classes and a driver program/...Assignment #4 will be the construction of 2 new classes and a driver program/...
Assignment #4 will be the construction of 2 new classes and a driver program/...
 
Data Storage
Data StorageData Storage
Data Storage
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
08ui.pptx
08ui.pptx08ui.pptx
08ui.pptx
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Intake 38 4
Intake 38 4Intake 38 4
Intake 38 4
 
projectreport
projectreportprojectreport
projectreport
 

More from smile790243

PART B Please response to these two original posts below. Wh.docx
PART B Please response to these two original posts below. Wh.docxPART B Please response to these two original posts below. Wh.docx
PART B Please response to these two original posts below. Wh.docxsmile790243
 
Part C Developing Your Design SolutionThe Production Cycle.docx
Part C Developing Your Design SolutionThe Production Cycle.docxPart C Developing Your Design SolutionThe Production Cycle.docx
Part C Developing Your Design SolutionThe Production Cycle.docxsmile790243
 
PART A You will create a media piece based around the theme of a.docx
PART A You will create a media piece based around the theme of a.docxPART A You will create a media piece based around the theme of a.docx
PART A You will create a media piece based around the theme of a.docxsmile790243
 
Part 4. Implications to Nursing Practice & Implication to Patien.docx
Part 4. Implications to Nursing Practice & Implication to Patien.docxPart 4. Implications to Nursing Practice & Implication to Patien.docx
Part 4. Implications to Nursing Practice & Implication to Patien.docxsmile790243
 
PART AHepatitis C is a chronic liver infection that can be e.docx
PART AHepatitis C is a chronic liver infection that can be e.docxPART AHepatitis C is a chronic liver infection that can be e.docx
PART AHepatitis C is a chronic liver infection that can be e.docxsmile790243
 
Part A post your answer to the following question1. How m.docx
Part A post your answer to the following question1. How m.docxPart A post your answer to the following question1. How m.docx
Part A post your answer to the following question1. How m.docxsmile790243
 
PART BPlease response to these two original posts below..docx
PART BPlease response to these two original posts below..docxPART BPlease response to these two original posts below..docx
PART BPlease response to these two original posts below..docxsmile790243
 
Part A (50 Points)Various men and women throughout history .docx
Part A (50 Points)Various men and women throughout history .docxPart A (50 Points)Various men and women throughout history .docx
Part A (50 Points)Various men and women throughout history .docxsmile790243
 
Part A1. K2. D3. N4. C5. A6. O7. F8. Q9. H10..docx
Part A1. K2. D3. N4. C5. A6. O7. F8. Q9. H10..docxPart A1. K2. D3. N4. C5. A6. O7. F8. Q9. H10..docx
Part A1. K2. D3. N4. C5. A6. O7. F8. Q9. H10..docxsmile790243
 
Part A Develop an original age-appropriate activity for your .docx
Part A Develop an original age-appropriate activity for your .docxPart A Develop an original age-appropriate activity for your .docx
Part A Develop an original age-appropriate activity for your .docxsmile790243
 
Part 3 Social Situations2. Identify multicultural challenges th.docx
Part 3 Social Situations2. Identify multicultural challenges th.docxPart 3 Social Situations2. Identify multicultural challenges th.docx
Part 3 Social Situations2. Identify multicultural challenges th.docxsmile790243
 
Part A (1000 words) Annotated Bibliography - Create an annota.docx
Part A (1000 words) Annotated Bibliography - Create an annota.docxPart A (1000 words) Annotated Bibliography - Create an annota.docx
Part A (1000 words) Annotated Bibliography - Create an annota.docxsmile790243
 
Part 6 Disseminating Results Create a 5-minute, 5- to 6-sli.docx
Part 6 Disseminating Results Create a 5-minute, 5- to 6-sli.docxPart 6 Disseminating Results Create a 5-minute, 5- to 6-sli.docx
Part 6 Disseminating Results Create a 5-minute, 5- to 6-sli.docxsmile790243
 
Part 3 Social Situations • Proposal paper which identifies multicul.docx
Part 3 Social Situations • Proposal paper which identifies multicul.docxPart 3 Social Situations • Proposal paper which identifies multicul.docx
Part 3 Social Situations • Proposal paper which identifies multicul.docxsmile790243
 
Part 3 Social Situations 2. Identify multicultural challenges that .docx
Part 3 Social Situations 2. Identify multicultural challenges that .docxPart 3 Social Situations 2. Identify multicultural challenges that .docx
Part 3 Social Situations 2. Identify multicultural challenges that .docxsmile790243
 
Part 2The client is a 32-year-old Hispanic American male who c.docx
Part 2The client is a 32-year-old Hispanic American male who c.docxPart 2The client is a 32-year-old Hispanic American male who c.docx
Part 2The client is a 32-year-old Hispanic American male who c.docxsmile790243
 
Part 2For this section of the template, focus on gathering deta.docx
Part 2For this section of the template, focus on gathering deta.docxPart 2For this section of the template, focus on gathering deta.docx
Part 2For this section of the template, focus on gathering deta.docxsmile790243
 
Part 2 Observation Summary and Analysis • Summary paper of observat.docx
Part 2 Observation Summary and Analysis • Summary paper of observat.docxPart 2 Observation Summary and Analysis • Summary paper of observat.docx
Part 2 Observation Summary and Analysis • Summary paper of observat.docxsmile790243
 
Part 2 Observation Summary and Analysis 1. Review and implement any.docx
Part 2 Observation Summary and Analysis 1. Review and implement any.docxPart 2 Observation Summary and Analysis 1. Review and implement any.docx
Part 2 Observation Summary and Analysis 1. Review and implement any.docxsmile790243
 
Part 2Data collectionfrom your change study initiative,.docx
Part 2Data collectionfrom your change study initiative,.docxPart 2Data collectionfrom your change study initiative,.docx
Part 2Data collectionfrom your change study initiative,.docxsmile790243
 

More from smile790243 (20)

PART B Please response to these two original posts below. Wh.docx
PART B Please response to these two original posts below. Wh.docxPART B Please response to these two original posts below. Wh.docx
PART B Please response to these two original posts below. Wh.docx
 
Part C Developing Your Design SolutionThe Production Cycle.docx
Part C Developing Your Design SolutionThe Production Cycle.docxPart C Developing Your Design SolutionThe Production Cycle.docx
Part C Developing Your Design SolutionThe Production Cycle.docx
 
PART A You will create a media piece based around the theme of a.docx
PART A You will create a media piece based around the theme of a.docxPART A You will create a media piece based around the theme of a.docx
PART A You will create a media piece based around the theme of a.docx
 
Part 4. Implications to Nursing Practice & Implication to Patien.docx
Part 4. Implications to Nursing Practice & Implication to Patien.docxPart 4. Implications to Nursing Practice & Implication to Patien.docx
Part 4. Implications to Nursing Practice & Implication to Patien.docx
 
PART AHepatitis C is a chronic liver infection that can be e.docx
PART AHepatitis C is a chronic liver infection that can be e.docxPART AHepatitis C is a chronic liver infection that can be e.docx
PART AHepatitis C is a chronic liver infection that can be e.docx
 
Part A post your answer to the following question1. How m.docx
Part A post your answer to the following question1. How m.docxPart A post your answer to the following question1. How m.docx
Part A post your answer to the following question1. How m.docx
 
PART BPlease response to these two original posts below..docx
PART BPlease response to these two original posts below..docxPART BPlease response to these two original posts below..docx
PART BPlease response to these two original posts below..docx
 
Part A (50 Points)Various men and women throughout history .docx
Part A (50 Points)Various men and women throughout history .docxPart A (50 Points)Various men and women throughout history .docx
Part A (50 Points)Various men and women throughout history .docx
 
Part A1. K2. D3. N4. C5. A6. O7. F8. Q9. H10..docx
Part A1. K2. D3. N4. C5. A6. O7. F8. Q9. H10..docxPart A1. K2. D3. N4. C5. A6. O7. F8. Q9. H10..docx
Part A1. K2. D3. N4. C5. A6. O7. F8. Q9. H10..docx
 
Part A Develop an original age-appropriate activity for your .docx
Part A Develop an original age-appropriate activity for your .docxPart A Develop an original age-appropriate activity for your .docx
Part A Develop an original age-appropriate activity for your .docx
 
Part 3 Social Situations2. Identify multicultural challenges th.docx
Part 3 Social Situations2. Identify multicultural challenges th.docxPart 3 Social Situations2. Identify multicultural challenges th.docx
Part 3 Social Situations2. Identify multicultural challenges th.docx
 
Part A (1000 words) Annotated Bibliography - Create an annota.docx
Part A (1000 words) Annotated Bibliography - Create an annota.docxPart A (1000 words) Annotated Bibliography - Create an annota.docx
Part A (1000 words) Annotated Bibliography - Create an annota.docx
 
Part 6 Disseminating Results Create a 5-minute, 5- to 6-sli.docx
Part 6 Disseminating Results Create a 5-minute, 5- to 6-sli.docxPart 6 Disseminating Results Create a 5-minute, 5- to 6-sli.docx
Part 6 Disseminating Results Create a 5-minute, 5- to 6-sli.docx
 
Part 3 Social Situations • Proposal paper which identifies multicul.docx
Part 3 Social Situations • Proposal paper which identifies multicul.docxPart 3 Social Situations • Proposal paper which identifies multicul.docx
Part 3 Social Situations • Proposal paper which identifies multicul.docx
 
Part 3 Social Situations 2. Identify multicultural challenges that .docx
Part 3 Social Situations 2. Identify multicultural challenges that .docxPart 3 Social Situations 2. Identify multicultural challenges that .docx
Part 3 Social Situations 2. Identify multicultural challenges that .docx
 
Part 2The client is a 32-year-old Hispanic American male who c.docx
Part 2The client is a 32-year-old Hispanic American male who c.docxPart 2The client is a 32-year-old Hispanic American male who c.docx
Part 2The client is a 32-year-old Hispanic American male who c.docx
 
Part 2For this section of the template, focus on gathering deta.docx
Part 2For this section of the template, focus on gathering deta.docxPart 2For this section of the template, focus on gathering deta.docx
Part 2For this section of the template, focus on gathering deta.docx
 
Part 2 Observation Summary and Analysis • Summary paper of observat.docx
Part 2 Observation Summary and Analysis • Summary paper of observat.docxPart 2 Observation Summary and Analysis • Summary paper of observat.docx
Part 2 Observation Summary and Analysis • Summary paper of observat.docx
 
Part 2 Observation Summary and Analysis 1. Review and implement any.docx
Part 2 Observation Summary and Analysis 1. Review and implement any.docxPart 2 Observation Summary and Analysis 1. Review and implement any.docx
Part 2 Observation Summary and Analysis 1. Review and implement any.docx
 
Part 2Data collectionfrom your change study initiative,.docx
Part 2Data collectionfrom your change study initiative,.docxPart 2Data collectionfrom your change study initiative,.docx
Part 2Data collectionfrom your change study initiative,.docx
 

Recently uploaded

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 

Recently uploaded (20)

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 

Lab 8 User-CF Recommender System – Part I 50 points .docx

  • 1. Lab 8 User-CF Recommender System – Part I 50 points In this lab, we will focus on understanding the design of a user- based collaborative filtering recommender system. Then we will implement half that design in this lab, and the other half in the next lab. System Description: A user-based collaborative filtering (User-CF for short) recommender works by making use of the similarities between users in a system. To recommend items for a specific user u, first User-CF finds the n-most similar users to u. These are called the neighbors of u. Then, the items that ratings that were given by the neighbors of u for the different items are used to generate recommendation scores for each item. Finally, the m items with the highest recommendation scores are recommended to u. The number of neighbors n, and the number of items m can vary based on the application in which the recommender is
  • 2. used. The overall flow of the user-based collaborative filtering recommendation process can be summarized in these steps: 1. Read movie information from file 2. Read user information from file 3. Generate movie recommendations for each user as follows. For each user u: a. Find u’s n most similar neighbors i. Compute the Jaccard similarity between u and all other users ii. Select the n users with the highest similarity values. Call these n users the neighbors of u. b. Compute movie recommendation scores for u as follows. i. For each movie, compute its recommendation score using the rating information for the neighbors of u. ii. Select the m movies with the highest recommendation scores. System Design: 1. The system will include a class named User to represent a
  • 3. user. That class should include the user’s ID, name, number of watched items, and a list containing the IDs of the watched items. The class should include a method for computing the number of similar items between two users. 2. To allow for representing diverse items, the system will include an abstract class named Item to represent a generic item. This class will include the item’s ID, name and description. 3. To represent movie items, the system will include a class named Movie that inherits from the abstract Item class. It will include the movie’s genre and director. 4. The system will contain a generic Recommender class that can be used to represent the basic information and behavior of any recommender technique. Specifically, it will contain the list of users, list of items, and an abstract method for generating recommendations. This class is abstract. 5. The system will contain a more specific recommender class, UserCFRecommender, that
  • 4. inherits from the generic Recommender class. It will contain methods that are specific to this recommendation technique. UML Diagram for the System Design: Recall the meanings of the UML Symbols: - Private + Public # Protected Lab Work: 1. You are provided with the java files containing all the class names along with the class variables and the method definitions. 2. You are required to implement the class methods that are shown in Bold Red in the UML diagram above. 3. The algorithm for each method is written, and commented, inside each method in the java files. 4. Don’t forget to implement a constructor for each class to
  • 5. initialize its data. Let your constructor print a message indicating successful initialization of the object data. 5. In your main method, create a UserCFRecommender object, and use it to read the items and users files. Then, print the user and item information to the console. The users and items files are also provided with the lab materials. 6. Run your main function and make sure that it is properly reading the users and items information. Lab Deliverables: 1. Zip all your code, along with a screen shot showing the output obtained after you compiled and run your code. Movie.txt 1 , Toy story , Adventure Animation 2 , Jumanji , Adventure Fantasy 3 , Grumpy Old Men , Comedy Romance 4 , Waiting to Exhale , Comedy Drama Romance 5 , Father of the Bride Part II , Comedy 6 , Heat , Action Crime Thriller 7 , Sabrina , Comedy Romance 8 , Tom and Huck , Adventure Children 9 , Sudden Death , Action
  • 6. 10 , GoldenEye , Action Adventure Thriller 11 , The American President , Comedy Drama Romance 12 , Dracula: Dead and Loving It , Comedy Horror 13 , Balto , Animation Children 14 , Nixon , Drama 15 , Cutthroat Island , Action Adventure Romance 16 , Casino , Crime Drama 17 , Sense and Sensibility , Comedy Drama Romance 18 , Four Rooms , Comedy Drama Thriller 19 , Ace Ventura: When Nature Calls , Comedy 20 , Money Train , Action Comedy Crime Drama Thriller item.java abstract public class Item{ //data protected int ID; protected String name; protected String description; //methods public Item() { ID = -1; name = ""; description = ""; } public Item(int ID, String n, String d) { this.ID = ID; this.name = n; this.description = d; } public int get_ID() {return ID;} public void set_ID(int i) {ID = i;} public String get_name() {return name;} public void set_name(String i) {name = i;} public String get_desciption() {return description;} public void set_description(String i) {description = i;}} movie.java public class Movie extends Item{ private String genre; private String director; //methods public Movie(int id, String n, String d, String g, String dir) { super(id, n, d); genre = g; director = dir; } public void set_genre(String g) {genre = g;} public String get_genre(String g) {return genre;} public void set_director(String g) {director = g;} public String
  • 7. get_director(String g) {return director;}} RecApp.java public class RecApp{ public static void main(String[] args) { UserCFRecommender ucf = new UserCFRecommender("", "movies.txt"); }} Recommender.java import java.util.Scanner;import java.io.*;public abstract class Recommender{ protected User[] users = new User[10]; protected Item[] items = new Item[10]; //========================= //========================= //reads items from a file protected void read_items(String file_name) { /* 1. Open the file 2. Read file line by line 3. For each line, Extract ID, Name, & Genre Create a Movie object Set Item ID, Name & Genre Add the Movie object into the Items[] items 6. Close the file */ try { File f = new File(file_name); Scanner s = new Scanner(f); while(s.hasNext()) { String[] vals = (s.nextLine()).split(" , "); for(int i=0; i< vals.length; i++) System.out.println(vals[i]); System.out.println(); } } catch (FileNotFoundException e) {} } //========================= //========================= protected void read_users(String file_name) { /* 1. Open the file 2. Read file line by line 3. For each line, Extract ID, n_items For i = 0 to n_items Extract the Movie IDs Create a User Object Set User ID, n_items, and add all items to that user. Add the User object into the
  • 8. Users[] users 4. Close the file */ } //========================= //========================= public User[] get_users() { return users; } //========================= //========================= public Item[] get_items() { return items; } //========================= //========================= public abstract void make_recommendations();} UserCFRecommender.java public class UserCFRecommender extends Recommender{ public UserCFRecommender() {} public UserCFRecommender(String ufile, String ifile) { read_items(ifile); read_users(ufile); } //computes the Jaccard similarity between two users give the //indices of both users in the Users[] users list. public double compute_jaccard_sim(int u1_ind, int u2_ind) { //1. get n_common_items: int n_common_items = (users[u1_ind]).similarity(users[u2_ind]); //2. get total_n_items using u1 n_items, u2 n_items & n_common_items //3. compute Jaccard sim as n_common_items/total_n_items return 0; } //finds the nieghbors of a user given the user index in the //Users[] users, and given the number of neighbors//returns neighbors indices, and neighbors similarity values public void find_user_neighbors(int u_ind, int n_neighbors, int[] n_ind, double[] n_sim) { /* 1. Create an array sim[] with size = n_users to save all similarity values in 2. For each other user u compute similarity between u_ind and u by calling the compute_jaccard_sim method, and save the result in sim[u] 3. Scan sim[] and select the "n_neighbors" users with the highest similarities. for i = 0 -> n_neighbors -1:
  • 9. ind = -1 max = -1 for j = 0 -> n_users -1: if sim[j]>max: max = sim[j] ind = j save max & ind into n_sim[i] and n_ind[i] set sim[ind] = -2 */ } // public void compute_recommendation_scores(int u_ind, int[] n_ind, double[] n_sim, double[] scores) { } // public void make_recommendations() {}} users.txt 1 4 1 2 10 192 3 1 6 193 3 1 2 74 2 1 105 4 1 5 7 116 6 1 7 11 18 19 207 5 1 2 7 11 178 5 5 9 11 16 199 7 1 2 3 6 9 10 1910 5 1 2 10 18 1911 3 1 2 1612 7 1 2 3 5 10 11 1913 9 1 2 3 5 10 11 13 19 2014 5 2 6 16 17 1915 6 1 3 5 6 10 16 User.java public class User{ //data private int ID; private String name; private int n_items; private int[] items = new int[100]; //methods public User() { ID = -1; name = ""; n_items = 0; } public User(int id, String n) { ID = id; name = n; n_items = 0; } public void add_item(int i) { items[n_items] = i; n_items++; } //computes the number of common items between this and u. public int similarity(User u) { int n = u.get_n_items(); int[] uitems = u.get_items(); int sim = 0; for(int i=0; i<n; i++) for(int j=0; j<n_items; j++) if(uitems[i] == items[j]){ sim++; break; } return sim; } public int get_ID() {return ID;} public int[] get_items() {return items;} public int get_n_items() {return n_items;} public int set_ID(int i) {ID = i;}}