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.

Files for aprioripy, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size aprioripy-0.0.2-py3-none-any.whl (3.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aprioripy-0.0.2.tar.gz (2.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page