Work Hours
Everyday: 北京时间8:00 - 23:59
1
Cardiff School of Computer Science and Informatics
Coursework Assessment Pro-forma
Module Code: CM1208
Module Title: Maths for Computer Science
Lecturer: Prof. Y. Lai
Assessment Title: Implementation of a simple e-commerce recommendation program
Assessment Number: 1
Date Set: 26th February 2021
Submission Date and Time: 23rd April 2021 at 9:30am
Return Date: within 4 weeks after submission via Learning Central
This assignment is worth 50% of the total marks available for this module. If coursework is
submitted late (and where there are no extenuating circumstances):
1 If the assessment is submitted no later than 24 hours after the deadline,
the mark for the assessment will be capped at the minimum pass mark;
2 If the assessment is submitted more than 24 hours after the deadline, a
mark of 0 will be given for the assessment.
Your submission must include the official Coursework Submission Cover sheet, which can be
found here:
https://docs.cs.cf.ac.uk/downloads/coursework/Coversheet.pdf
Submission Instructions
All submission should be via Learning Central unless agreed in advance with the Director of Teaching. The current electronic
coursework submission policy can be found at:
http://www.cs.cf.ac.uk/currentstudents/ElectronicCourseworkSubmissionPolicy.pdf
Write a Python application program (main file called Recommend.py) that implements e-commerce
recommendation based on item-to-item collaborative filtering, as discussed in the lectures.
Description Type Name
Cover sheet Compulsory One PDF (.pdf) file [student number].pdf
Q1 Compulsory One Python source file (.py) Recommend.py
Optional Additional Python source files (.py) No restriction
Any deviation from the submission instructions above (including the number and types of
files submitted) will result in a mark of zero for the assessment or question part.
Staff reserve the right to invite students to a meeting to discuss coursework submissions
CM1208: Maths for Computer Science coursework 2020/21
ASSIGNMENT
Write a Python application program (main file called Recommend.py) that implements e-commerce recommendation based on item-to-item collaborative filtering, as discussed in the lectures.
Input and Output. The input to your program involves two text files history.txt which contains
the purchase history of all the customers and queries.txt which includes all the queries (shopping cart
items based on which you need to provide recommendation).
The file history.txt is a text file describing the complete purchase history of all the customers. The first
line includes three numbers:
Number of Customers Number of Items Number of Transactions
This is followed by Number of Transactions lines of text, each line containing two numbers:
Customer ID Item ID
This means the customer Customer ID bought the item Item ID. Both Customer ID and Item ID are
integers starting from 1. Note that the same customer may have bought the same item multiple times.
The file queries.txt is a text file with each line containing a query, describing a list of items in the current
shopping cart. Each query is composed of one or more numbers, separated by whitespace, corresponding
to the item IDs in the current shopping cart. All the input files described above are assumed to be in the
current folder. Your program should read from these files in the current folder without any user interaction.
Do not ask users to enter paths or filenames.
For output, print the required messages (see details below and sample outputs overleaf) following exactly
the same format (except for the actual number of whitespace) as specified and as in the examples. When
printing real numbers, you should print them with at least two fractional digits.
Reading the transaction history. Your program should read in all the transactions from history.txt,
and build the customer-item purchase history table (as explained in the lecture) where an entry of 1 means
the customer has bought the item and 0 otherwise. Print the total number of non-zero entries (i.e. with a
value of 1) in the customer-item purchase history table (“Positive entries: number”).
Precomputing item-to-item angles. Your program should work out the angles (in degrees) between
every pair of items (excluding an item with itself). Print the average of all the pairwise angles (“Average
angle: average angle”).
Recommendation. For each query (each line in queries.txt), your program should perform the following:
- Print the query in a line “Shopping cart: query”.
- For each item Item ID in the query (in the order as it appears), find an item Match ID not in the
current shopping cart which has the minimum angle Min Angle with the item Item ID.
– If Min Angle is less than 90◦
, print “Item: Item ID; match: Match ID; angle: Min Angle”.
– Otherwise, no match is accepted, and you should simply print “Item: Item ID no match”.
Note that when multiple items have the same minimum angle, your algorithm can print any one of
these. Each printed item Match ID is considered as a candidate for recommendation. - Produce the recommendation list by combining all the candidates and order them in increasing order of
angles. For items which are considered relevant via different shopping cart items, the minimum angle
it makes with any item in the shopping cart should be used in ranking, and it should only appear in the
recommendation list once. If multiple candidates have the same angle, they may appear in arbitrary
order. Print “Recommend: list of recommended items”.
Error checking is not required (invalid input, etc.) Remember that I will perform extensive tests on your
program, using more than just the test data I have provided.
Hint: The Week 5 exercise sheet (to be available under Learning Materials → Week 5 (01/03/2021))
includes exercises related to handling text files using Python, which can be useful. Several further test cases
and their expected output are provided on learning central. 2
CM1208: Maths for Computer Science coursework 2020/21
LEARNING OUTCOMES ASSESSED
- Show awareness of different aspects of mathematics in analysing and understanding important areas
of computing - Appreciate how mathematical techniques contribute to the study of computing
- Apply mathematical techniques and knowledge to a problem or situation
- Demonstrate an awareness of solving practical problems using mathematics and Python programming
CRITERIA FOR ASSESSMENT
Assessment and marking of your program will be done by automatically checking the output of your
program against my program on a large set of test conditions. This will be done using a text comparison
tool, so make sure your outputs match mine as formatting of text will be critical!
Note that extra blank spaces are ignored (so are acceptable), and when printing numbers you may print
more fractional digits than the example shown below.
An implementation that does not exactly follow the assignment instructions, including text
formatting not matching the description and examples shown in the assignment, may result
in a deduction of up to 50% of marks for the relevant features.
The breakdown of marks will be:
- 10% – reading in purchase history
- 25% – precomputing item-to-item angles
- 5% – reading and printing queries
- 30% – working out candidate for each item in the shopping cart
- 15% – printing recommendation in the correct order
- 15% – efficiency (i.e. excessive run-times will be penalised)
FURTHER DETAILS
Feedback on your coursework will address the above criteria and will be returned in approximately four
working weeks. This will be supplemented with oral feedback in an online practical session. If you have any
questions relating to your individual solutions talk to the lecturer.
3
CM1208: Maths for Computer Science coursework 2020/21
Sample Outputs
Given the following history.txt:
5 5 12
1 1
1 2
2 1
2 3
3 1
3 2
3 4
4 2
4 4
1 2
2 3
5 5
and the following queries.txt:
2
1 2
5
5 1
5 1 4
1 3 5
the exact output of your program should be:
Positive entries: 10
Average angle: 74.41
Shopping cart: 2
Item: 2; match: 4; angle: 35.26
Recommend: 4
Shopping cart: 1 2
Item: 1; match: 3; angle: 54.74
Item: 2; match: 4; angle: 35.26
Recommend: 4 3
Shopping cart: 5
Item: 5 no match
Recommend:
Shopping cart: 5 1
Item: 5 no match
Item: 1; match: 2; angle: 48.19
Recommend: 2
Shopping cart: 5 1 4
Item: 5 no match
Item: 1; match: 2; angle: 48.19
Item: 4; match: 2; angle: 35.26
Recommend: 2
Shopping cart: 1 3 5
Item: 1; match: 2; angle: 48.19
Item: 3 no match
Item: 5 no match
Recommend: 2
4
https://data.cardiff.ac.uk/legacy/grails/module/CM1208/17A.html