We are given four items, namely A, B, C, and D. Their corresponding unit profits are pA, pB, pC, and pD. The following shows five transactions with these items. Each row corresponds to a transaction where a non-negative integer shown in the row corresponds to the total number of occurrences of the correspondence item present in the transaction.
T |
A |
B |
C |
D |
t1 |
0 |
0 |
3 |
2 |
t2 |
3 |
4 |
0 |
0 |
t3 |
0 |
0 |
1 |
3 |
t4 |
1 |
0 |
3 |
5 |
t5 |
6 |
0 |
0 |
0 |
Let f be a function defined on an itemset s (f will be specified later). One example of this functions is
f (s) = i∈s pi. In this example, if s = {C, D}, then f (s) = pC+ pD.
Answer the following question based on the above problem setting.
Assume f (s) = i∈s pi. Suppose that we know pA= 5, pB= 10, pC= 6, and pD= 4. We want to find all itemsets with profit at least 50. Can the Apriori Algorithm be adapted to find these itemsets? If yes, please write down the pseudo-code and illustrate it with the above example. If no, please explain why. In this case, please also design an algorithm for this problem and write down the pseudo-code.
class compare():
def __init__(self):
self.dic = {}
self.flis = {}
def adding2(self,x,y):
#print("a")
checks = self.dic.get(x)
if checks is not None:
#print("checks")
for check in checks:
#print(check[0])
#print(x,y)
#print(check[0])
if y == check[0]:
break
else:
if check[0]==checks[len(checks)-1][0]:
if x>y:
self.dic[x].append((y,True))
checkys = self.dic.get(y)
if checkys is not None:
for checky in checkys:
if x == checky[0]:
break
else:
if checky[0]==checkys[len(checkys)-1][0]:
self.dic[y].append((x,False))
else:
self.dic[y]=[]
self.dic[y].append((x,False))
else:
self.dic[x].append((y,False))
checkys = self.dic.get(y)
if checkys is not None:
for checky in checkys:
if x == checky[0]:
break
else:
if checky[0]==checkys[len(checkys)-1][0]:
self.dic[y].append((x,True))
else:
self.dic[y]=[]
self.dic[y].append((x,True))
break
else:
self.dic[x]=[]
#print("c")
if x>y:
self.dic[x].append((y,True))
checkys = self.dic.get(y)
if checkys is not None:
for checky in checkys:
if x == checky[0]:
break
else:
if checky[0]==checkys[len(checkys)-1][0]:
self.dic[y].append((x,False))
else:
self.dic[y]=[]
self.dic[y].append((x,False))
else:
self.dic[x].append((y,False))
checkys = self.dic.get(y)
if checkys is not None:
for checky in checkys:
if x == checky[0]:
break
else:
if checky[0]==checkys[len(checkys)-1][0]:
self.dic[y].append((x,True))
else:
self.dic[y]=[]
self.dic[y].append((x,True))
def myfunc(self,x,y):
self.adding2(x,y)
def arrfunc(self,nums):
self.lis= nums
i = len(nums)
# print(3>0)
for x in range(0,i):
for y in range(x,i):
#print(nums[x],nums[y])
#if nums[x]!=nums[y]:
#print(nums[x],nums[y])
self.myfunc( nums[x],nums[y])
#print(self.dic)
for x in self.dic:
count=1
res = self.dic.get(x)
for ress in res:
if ress[1] is True:
count=count+1
self.flis[x]=count
#print(self.dic)
print(self.flis)
if __name__ == "__main__":
obj = compare()
lis = [60,51,87,40]
obj.arrfunc(lis)
We are given four items, namely A, B, C, and D. Their corresponding unit profits are...
Table 1: Data set of market-basket transactions ansaction ID Items Bought [A, B, D, E (B, C, D (A, B, D, E) A, C, D, E) (B,C, D, E B, D, E (C, D) (A, B, C (A, D, E) 6 7 [15 points] Answer the following questions for the data set in Table 1. (a) What is the maximum number of association rules that can be extracted from this data set (including rules that have zero support)? (b) What...
Consider that we have four classes—A, B, C, & D—of 100 items each that constitute our sample set. The expected information to classify a given sample is ? A. 0 B. 1 2 C. 1 D. 2 E. π Show your calculations to reach the question..
Haloo , i have java program , Java Program , dynamic program Given a knapsack with capacity B∈N and -n- objects with profits p0, ..., p n-1 and weights w0, ..., wn-1. It is also necessary to find a subset I ⊆ {0, ..., n-1} such that the profit of the selected objects is maximized without exceeding the capacity. However, we have another limitation: the number of objects must not exceed a given k ∈ N Example: For the items...
One unit of A is made of one unit of B and one unit of C. B is made of four units of C and one unit each of E and F. C is made of two units of D and one unit of E. E is made of three units of F. Item C has a lead time of one week; Items A, B, E, and F have two-week lead times; and Item D has a lead time of...
One unit of A is made of one unit of B and one unit of C. B is made of four units of C and one unit each of E and F. C is made of two units of D and one unit of E. E is made of three units of F. Item C has a lead time of one week; Items A, B, E, and F have two-week lead times; and Item D has a lead time of...
2. Suppose a matrix has four blocks A, B,C, D, where A is invertible. Block elimination can be done on this block matrix. For example, consider what happens when CA-1 times the first block row [A B] is subtracted from the second block row [C D 0 D - CA B Note: S = D-CA-B is called the Schur complement of A. (a) (3 points) Find X and Y such that AB (b) (3 points) Find S for A B
We already know the functions defined by y =C+a•f[b(x-d)] with the assumption that b>0. To see what happens when b<0, work parts (a)-(f) in order. (a) Use an even-odd identity to write y = sin(-2x) as a function of 2x. y= (b) How is your answer to part (a) related to y = sin(2x)? O It is the negative of y = sin (2x). olt equals y = sin (2x). (c) Use an even-odd identity to write y = cos(...
We already know the functions defined by y =c+a+f[b(x-d)] with the assumption that b>0. To see what happens when b<0, work parts (a)-(f) in order. (a) Use an even-odd identity to write y = sin (-2x) as a function of 2x. y = (b) How is your answer to part (a) related to y = sin (2x)? O It is the negative of y=sin (2x). It equals y=sin (2x). (c) Use an even-odd identity to write y = cos(-5x) as...
The Hungarian algorithm: An example We consider an example where four jobs (J1, J2, J3, and J4) need to be executed by four workers (W1, W2, W3, and W4), one job per worker. The matrix below shows the cost of assigning a certain worker to a certain job. The objective is to minimize the total cost of the assignment. J1 J2 J3 J4 W1 82 83 69 92 W2 77 37 49 92 W3 11 69 5 86 W4 8...
One unit of A is made of three units of B, one unit of C, and two units of D. B is composed of two units of E and one unit of D. C is made of one unit of B and two units of E. E is made of one unit of F. Items B, C, E, and F have one-week lead times; A and D have lead times of two weeks. Assume that lot-for-lot (L4L) lot sizing is...