Skip to content

Commit

Permalink
codi net
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariona-FT committed Dec 13, 2023
1 parent 6016b6b commit 018e994
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
5 changes: 2 additions & 3 deletions lab5/MRMarketBasket1.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def mapper(self, _, line):
:param line: contains a transaction
"""
# Each line is a string a,b,c
# Return pair key, value

trans = line.strip().split(',')
for i in range(len(trans)):
for j in range(len(trans)):
Expand All @@ -36,7 +35,7 @@ def reducer(self, key, values):
Output should be at least a pair (key, new counting)
"""
# Compute reducer here

yield key, sum(values)


Expand Down
7 changes: 2 additions & 5 deletions lab5/MRMarketBasket2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ def mapper(self, _, line):
:param line: contains a transaction
"""
# Each line is a string a,b,c
trans = line.strip().split(',')
# Compute map here

trans = line.strip().split(',')
for item in trans:
yield item, 1
# Return pair key, value



Expand All @@ -37,7 +34,7 @@ def reducer(self, key, values):
Output should be at least a pair (key, new counting)
"""
# Compute reducer here

yield key, sum(values)


Expand Down
6 changes: 2 additions & 4 deletions lab5/MRMarketBasketAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
# Process the results of the script iterating the (key,value) pairs
for key, value in mr_job1.parse_output(runner1.cat_output()):
pairs[tuple(key)]=value
# You should store things here probably in a data structure


mr_job2 = MRMarketBasket2(args=['-r', 'local', args.file,'--num-cores', str(args.ncores)])
Expand All @@ -49,7 +48,6 @@
singles = {}
for key, value in mr_job2.parse_output(runner2.cat_output()):
singles[key]=value
# You should store things here probably in a data structure

print(f'Time= {(time.time() - tinit)} seconds')

Expand All @@ -65,14 +63,14 @@
print("******************************************************************************* ")

for support, conf in [(0.01,0.01), (0.01,0.25), (0.01,0.5), (0.01,0.75), (0.05,0.25), (0.07,0.25), (0.20,0.25), (0.5,0.25)]:
nr = 0 # Inicializar el contador de reglas
nr = 0 # Contador de reglas
for pair, pair_count in pairs.items():
item1, item2 = pair
if item1 in singles and item2 in singles:
sup = pair_count / ntrans
confi = pair_count / singles[item1]
if sup >= support and confi >= conf:
nr += 1 # Contar la regla si cumple con el soporte y la confianza
nr += 1 # Contar la regla si compleix support i la confidence

print("Support=", str(support), "confidence=", str(conf) + ".", "Rules found", nr, '\n')

Expand Down

0 comments on commit 018e994

Please sign in to comment.