From 7787c679d43008356388e2cdf9d39c2948b31fef Mon Sep 17 00:00:00 2001 From: kouamschekina Date: Fri, 8 Dec 2023 16:41:09 +0100 Subject: [PATCH 1/4] fix(main):explanation of the code using comments --- main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index d74dd52..7514305 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,7 @@ from src.apriori import apriori if __name__ == '__main__': - result = apriori([[1, 2, 3], [1, 2, 3], [1, 2, 3]], 0.3, 0.7) - print(result) + #assigning the value of apriori to the results variable + results = apriori([[1, 2, 3], [1, 2, 3], [1, 2, 3]], 0.3, 0.7) + #display results + print(results) From 9f9256c6bf24bac31b45bca326d66b97f1d9b724 Mon Sep 17 00:00:00 2001 From: kouamschekina Date: Fri, 8 Dec 2023 17:16:17 +0100 Subject: [PATCH 2/4] fix(main):explanation of the code using comments --- main.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 7514305..788590e 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,17 @@ from src.apriori import apriori +def multiplication(): + try: + a = input(float("enter the first number")) + b = input(float("enter the second number")) + product = (a*b) + return product + except ValueError: + return("enter a valid number") + if __name__ == '__main__': #assigning the value of apriori to the results variable - results = apriori([[1, 2, 3], [1, 2, 3], [1, 2, 3]], 0.3, 0.7) - #display results - print(results) + result = apriori([[1, 2, 3], [1, 2, 3], [1, 2, 3]], 0.3, 0.7) + #display result + print(result) +multiplication() \ No newline at end of file From 3038e5c40159f414d12b3076dc41086572cccb91 Mon Sep 17 00:00:00 2001 From: kouamschekina Date: Sat, 9 Dec 2023 12:05:45 +0100 Subject: [PATCH 3/4] feat(global): Implementation of the support and confidence scripts --- main.py | 11 +---------- notebook/support.ipynb | 19 ++++--------------- src/confidence.py | 11 ++++++++++- src/support.py | 8 ++++++++ 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/main.py b/main.py index 788590e..7418b05 100644 --- a/main.py +++ b/main.py @@ -1,17 +1,8 @@ from src.apriori import apriori -def multiplication(): - try: - a = input(float("enter the first number")) - b = input(float("enter the second number")) - product = (a*b) - return product - except ValueError: - return("enter a valid number") - if __name__ == '__main__': #assigning the value of apriori to the results variable result = apriori([[1, 2, 3], [1, 2, 3], [1, 2, 3]], 0.3, 0.7) #display result print(result) -multiplication() \ No newline at end of file + \ No newline at end of file diff --git a/notebook/support.ipynb b/notebook/support.ipynb index 29cd743..8900730 100644 --- a/notebook/support.ipynb +++ b/notebook/support.ipynb @@ -1,16 +1,5 @@ { - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "id": "initial_id", - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], + "cells": [], "metadata": { "kernelspec": { "display_name": "Python 3", @@ -20,14 +9,14 @@ "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" + "pygments_lexer": "ipython3", + "version": "3.10.12" } }, "nbformat": 4, diff --git a/src/confidence.py b/src/confidence.py index ba640e4..69887de 100644 --- a/src/confidence.py +++ b/src/confidence.py @@ -1,9 +1,18 @@ +import support dataset_type = list[list[object]] rule_type = tuple[list[object], list[object]] def confidence(data_set: dataset_type, rule: rule_type) -> float: + + support_AB = support(data_set, rule[0] + rule[1]) + support_A = support(data_set, rule[0]) + if support_A != 0 : + confidence = support_AB / support_A + else: + confidence = 0 + return confidence """ To measure the likelihood of occurrence of an itemset given another itemset. """ - pass +pass diff --git a/src/support.py b/src/support.py index 130e148..9ba4d0d 100644 --- a/src/support.py +++ b/src/support.py @@ -3,6 +3,14 @@ def support(itemsets: dataset_type, data_set: itemset_type) -> float: + count = 0 + for transaction in itemsets: + total_transactions = len(itemsets) + if set(data_set).issubset(transaction): + count += 1 + support = count / total_transactions + return support + """ To find the frequency of itemsets in the dataset. """ From ea6a3796303e3723b73b64b153243f2b280274dc Mon Sep 17 00:00:00 2001 From: kouamschekina Date: Mon, 11 Dec 2023 09:01:35 +0100 Subject: [PATCH 4/4] fix(main):explanation of the code using comments --- src/apriori.py | 3 ++- test/test_support.py | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apriori.py b/src/apriori.py index 957c524..088a379 100644 --- a/src/apriori.py +++ b/src/apriori.py @@ -9,4 +9,5 @@ def apriori(transactions: list[list[object]], min_support: float = 0.7, min_conf """ To find all frequent itemsets in a dataset and generate strong association rules. """ - return {}, {} + + return frequent_items, strong_rules diff --git a/test/test_support.py b/test/test_support.py index a4b17ad..405005d 100644 --- a/test/test_support.py +++ b/test/test_support.py @@ -1,5 +1,4 @@ import unittest - from src.support import support as calc_support