Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature implementing aprior algorithm #13

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from src.apriori import apriori

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)
print(result)
print(result)
2 changes: 1 addition & 1 deletion src/apriori.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ def get_subsets(itemset: List[object]) -> List[List[object]]:





16 changes: 16 additions & 0 deletions src/confidence.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import support
dataset_type = list[list[object]]
rule_type = tuple[list[object], list[object]]
from typing import List, Tuple
from support 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

def confidence(dataset: dataset_type, rule: rule_type) -> float:
"""
Expand Down
8 changes: 8 additions & 0 deletions src/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
dataset_type = List[List[object]]

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.
"""
Expand Down
1 change: 0 additions & 1 deletion test/test_support.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import unittest

from src.support import support as calc_support


Expand Down