HW 1
HW 1
Homework 1
Deadline: 10 Oct, 2023 3pm
(Please hand in during lecture.)
Full Mark: 100 Marks
Coupon Instructions:
1. You can use a coupon to waive any question you want and obtain full marks for this question.
2. You can waive at most one question in each assignment.
3. You can also answer the question you will waive. We will also mark it but will give full marks to this
question.
4. The coupon is non-transferrable. That is, the coupon with a unique ID can be used only by the student
who obtained it in class.
5. Please staple the coupon to the submitted assignment.
6. Please write down the question no. you want to waive on the coupon.
Q1 [20 Marks]
(a) In general, we have a number of customers. For illustration, we are given two customers, namely X and
Y. The following shows 5 transactions for these two customers. Each transaction contains three kinds of
information: (1) customer ID (e.g., X and Y), (2) the time that this transaction occurred, and (3) all the
items involved in this transaction.
For example, the first transaction corresponds to that customer X bought item A, item B and item C at
time 1, while the last transaction corresponds to that customer Y bought item D, item E and item G at
time 5.
A sequence is defined to be a series of itemsets in form of <S1, S2, S3, …, Sm> where Si is an itemset for
i = 1, 2, …, m. The above transactions can be transformed into two sequences as follows.
Given a sequence S in form of <S1, S2, S3, …, Sm> and another sequence S’ in form of <S1’, S2’, S3’, …,
Sn’> , S is said to be a subsequence of S’ if m n and there exist m integers, namely i1, i2, …, im, such
that (1) 1i1<i2< …< imn, and (2) Sj Si j’ for j = 1, 2, …, m. If S is a subsequence of S’, then S’ is
defined to be a super-sequence of S.
The support of a sequence S is defined to be the total number of customers which sequences are super-
sequences of S.
Given a positive integer k, a sequence in form of <S1, S2, S3, …, Sm> is said to be a k-sequence if
m
|Si|=k.
i1
1/5
Can the Apriori algorithm be adapted to mining all k-sequences with support at least 2 where k = 2, 3,
4, …. ? If yes, please write down the proposed method using the concept of the Apriori algorithm and
illustrate your algorithm with the above example. If no, please explain the reason.
(b) We want to study the same problem setting described in (a). However, each customer is associated to
one binary attribute called “Rich” to indicate whether this customer is rich or not. There are only 2
possible values in this attribute, namely “Yes” and “No”. In our example, customer X could have “Yes”
in attribute “Rich” and customer Y could have “No” in attribute “Rich”.
Given a k-sequence S and a value v in attribute “Rich”, the support of a sequence S with respect to value
v is defined to be the total number of customers which sequences are super-sequences of S and are
associated with value v in attribute “Rich”. The important ratio of S is defined to be the support of S
with respect to value “Yes” divided by the support of S with respect to value “No”.
Can the Apriori algorithm be adapted to mining all k-sequences with important ratio at least 2 and the
support at least 1 where k = 2, 3, 4, ….? If yes, please write down the proposed method using the
concept of the Apriori algorithm and illustrate your algorithm with the above example. If no, please
explain the reason.
Note that when we compute the important ratio, if we encounter a division of a non-zero number by zero,
we could regard it as a positive infinity value.
2/5
Q2 [20 Marks]
The following shows four transactions with six items. Each row corresponds to a transaction where 1
corresponds to a presence of an item and 0 corresponds to an absence.
A B C D E F
0 0 1 1 0 0
0 1 0 0 1 1
1 0 1 1 0 0
1 0 1 1 0 0
It seems that it is troublesome to set one more parameter in the problem of finding SK, l (compared
with the traditional frequent itemset mining you learnt). What are the advantages of the problem of
finding SK, l compared with the traditional problem?
3/5
Q3 [20 Marks]
x1:(17, 12), x2: (5, 12), x3: (17, 14), x4: (5, 16), x5: (20, 15), x6: (3, 9), x7: (12, 3), x8: (12, 32)
Q4 [20 Marks]
(a) Please use the agglomerative approach to group these points with distance group average linkage.
Draw the corresponding dendrogram for the clustering. You are required to specify the distance metric
in the dendrogram.
(b) Suppose that we want to find 4 clusters. According to the dendrogram in (a), please state the 4 clusters.
For each cluster, please include all data points involved.
(c) (i) What is the greatest possible number of data points in a cluster containing data 1 and data 5?
(ii) What is the smallest possible number of data points in a cluster containing data 1 and data 5?
(d) Suppose that data points satisfy the triangle inequality. That is, for any three data points, a, b and c, we
have |a, b| + |b, c| |a, c| where |a, b| denotes the pairwise distance between a and b, and |b, c| and |a, c|
have similar meanings. Does the triangle inequality enhance the agglomerative approach? If yes, please
elaborate it. If no, please give the reason.
4/5
Q5 [20 Marks]
(a) In class, we learnt k-means where the center of each cluster is the “average” or “mean” of all data points
assigned to this cluster. k-medoids is exactly the same as k-means except that the center of each cluster is
defined to be one of the data points assigned to this cluster which has the minimum average distance
between this point and another point assigned to this cluster.
One disadvantage of method k-medoids is that all data points given are based on numeric attributes only.
The major principle of k-medoids is to find the closest center for each data point and update the center of
each cluster with all points assigned to this cluster iteratively.
Consider that the data points have only categorical attributes. We would like to adopt the major principle of
k-medoids for clustering on these data points. Please write down how you adapt this k-medoids method for
this purpose.
(b) Another disadvantage of method k-means is that k (i.e., the number of clusters) should be pre-
determined.
One may suggest the following method to determine parameter k.
Step 1: Set variable e0 to
Step 2: Set k to 1 initially
Step 3: Run the original k-means method and obtain k cluster centers (or means)
Step 4: Set variable ek to the sum of the distances between points and their closest cluster centers
(according to the k cluster centers found).
Step 5: If ek converges (i.e., (ek-1 – ek) is equal to 0 or an extremely small number), then return k.
Otherwise, increment k by 1 and repeat Step 3 to Step 4.
Can the above method determine a good value for k (i.e., the number of clusters)? Please explain.
If your answer is no, please also give an algorithm to determine a good value for k and explain why it is
better than the above method.
5/5