apetkau / comp7944-project

Project on visualizing association rules extracted from covid-19 data.
Apache License 2.0
1 stars 1 forks source link

Apriori Implementation using 'apyori' Library #2

Open walid-shaiket opened 4 years ago

walid-shaiket commented 4 years ago

import pandas as pd import numpy as np import matplotlib.pyplot as plt from apyori import apriori

store_data = pd.read_csv('D:/MSc_UofM/Data Mining/Project/DataSets/symptoms.tsv',delimiter="\t", header=None)

store_data.head()

count_row = store_data.shape[0] # gives number of row count count_col = store_data.shape[1] # gives number of col count

print(count_row)

print(count_col)

records = [] for i in range(0, 1519): records.append([str(store_data.values[i,j]) for j in range(0, 6)])

association_rules = apriori(records, min_support=0.0045, min_confidence=0.2, min_lift=3, min_length=2) association_results = list(association_rules)

print(len(association_results))

print(association_results[0])

for item in association_results:

# first index of the inner list
# Contains base item and add item
pair = item[0] 
items = [x for x in pair]
print("Rule: " + items[0] + " -> " + items[1])

#second index of the inner list
print("Support: " + str(item[1]))

#third index of the list located at 0th
#of the third index of the inner list

print("Confidence: " + str(item[2][0][2]))
print("Lift: " + str(item[2][0][3]))
print("=====================================")

output

generated_rules_using_apyori_library

walid-shaiket commented 4 years ago

Just compare, which one is useful for visualization