Question

We are given four items, namely A, B, C, and D. Their corresponding unit profits are...

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

  • The frequency of an itemset in a row is defined to be the minimum of the number of occurrences of      all items in the itemset. For example, itemset {C, D} in the first row has frequency equals 2. But, itemset {C, D} in the third row has frequency as 1.
  • The frequency of an itemset in the dataset is defined to be the sum of the frequencies of the itemset in all rows in the dataset. For example, itemset {C, D} has frequency 2+0+1+3+0=6.

Let f be a function defined on an itemset s (f will be specified later). One example of this functions is

f (s) = is pi. In this example, if s = {C, D}, then f (s) = pC+ pD.

  • The profit of an itemset s in the dataset is defined to be the product of the frequency of this itemset in the dataset and f (s). For example, itemset {C, D} has profit 6 × f ({C, D}).

Answer the following question based on the above problem setting.

Assume f (s) = is 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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)

Add a comment
Know the answer?
Add Answer to:
We are given four items, namely A, B, C, and D. Their corresponding unit profits are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT