Skip to main content

Apriori algorithm.

Project description

Aprioripy: Apriori algorithm.

Apriori algorithm usage:

from apriopy import Apriopy


test_table = pd.DataFrame({
    "items": ["1, 3, 4", "2, 3, 5", "1, 2, 3, 5", "2, 5"]
})

print("Test table")
print(test_table)

ap = Aprioripy(table=test_table)

print("\nFrequency table:")
print(ap.frequency_table)

ap.apriori(min_support=0.5)

for i in ap.association_tables.keys():
    print("\nAssociation table " + i)
    print(ap.association_tables[i])

test_table = pd.DataFrame(
    [
        {"1": 1, "2": 0, "3": 1, "4": 1, "5": 0},
        {"1": 0, "2": 1, "3": 1, "4": 0, "5": 1},
        {"1": 1, "2": 1, "3": 1, "4": 0, "5": 1},
        {"1": 0, "2": 1, "3": 0, "4": 0, "5": 1}
    ]
)

print("\nTest table:")
print(test_table)

ap = Aprioripy(table=test_table, convert=False)

print("\nFrequency table:")
print(ap.frequency_table)

ap.apriori(min_support=0.5)

for i in ap.association_tables.keys():
    print("\nAssociation table " + i)
    print(ap.association_tables[i])

Output:

Test table
        items
0     1, 3, 4
1     2, 3, 5
2  1, 2, 3, 5
3        2, 5

Frequency table:
  item  frequency
0    1       0.50
1    2       0.75
2    3       0.75
3    4       0.25
4    5       0.75

Association table L1
  item  frequency
0    1       0.50
1    2       0.75
2    3       0.75
4    5       0.75

Association table L2
  itemset  frequency
1  (1, 3)       0.50
4  (2, 3)       0.50
6  (2, 5)       0.75
8  (3, 5)       0.50

Association table L3
     itemset  frequency
7  (2, 3, 5)        0.5

Test table:
   1  2  3  4  5
0  1  0  1  1  0
1  0  1  1  0  1
2  1  1  1  0  1
3  0  1  0  0  1

Frequency table:
  item  frequency
0    1       0.50
1    2       0.75
2    3       0.75
3    4       0.25
4    5       0.75

Association table L1
  item  frequency
0    1       0.50
1    2       0.75
2    3       0.75
4    5       0.75

Association table L2
  itemset  frequency
1  (1, 3)       0.50
4  (2, 3)       0.50
6  (2, 5)       0.75
8  (3, 5)       0.50

Association table L3
     itemset  frequency
7  (2, 3, 5)        0.5

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aprioripy-0.0.2.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distribution

aprioripy-0.0.2-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page