<jupyter_start><jupyter_text>Data Mining and Machine Learning Association Rules using the apyori module <NAME> May 2021<jupyter_code>import numpy as np  
import pandas as pd  
from apyori import apriori<jupyter_output><empty_output><jupyter_text>Market basket of 7501 transactions and 20 items<jupyter_code>#the data is available at https://stackabuse.com/association-rule-mining-via-apriori-algorithm-in-python/
store_data = pd.read_csv('https://academic.uprm.edu/eacuna/store_data.csv',header=None)  
store_data.head()  
#converting the dataframe in a list
records = []  
for i in range(0, 7501):  
    records.append([str(store_data.values[i,j]) for j in range(0, 20)])
association_rules = apriori(records, min_support=0.007, min_confidence=0.2, min_lift=3, min_length=2)  
association_results = list(association_rules)  
print(len(association_results))
#printing the first two results
association_results[0:2]  
#Printing the  association rules
for item in association_results:

    # first index of the inner list
    # Contains base item and add item
    pair = item[0] 
    print(pair)
    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("=====================================")<jupyter_output>frozenset({'ground beef', 'herb & pepper'})
Rule: ground beef -> herb & pepper
Support: 0.015997866951073192
Confidence: 0.3234501347708895
Lift: 3.2919938411349285
=====================================
frozenset({'olive oil', 'whole wheat pasta'})
Rule: olive oil -> whole wheat pasta
Support: 0.007998933475536596
Confidence: 0.2714932126696833
Lift: 4.122410097642296
=====================================
frozenset({'ground beef', 'spaghetti', 'frozen vegetables'})
Rule: ground beef -> spaghetti
Support: 0.008665511265164644
Confidence: 0.31100478468899523
Lift: 3.165328208890303
=====================================
frozenset({'mineral water', 'shrimp', 'frozen vegetables'})
Rule: mineral water -> shrimp
Support: 0.007199040127982935
Confidence: 0.30508474576271183
Lift: 3.200616332819722
=====================================
frozenset({'ground beef', 'nan', 'herb & pepper'})
Rule: ground beef -> nan
Support: 0.015997866951073192
Confidence: 0.3234501347708895
Lift: 3.2919938411349285[...]
{'fraction_non_alphanumeric': 0.18509615384615385, 'fraction_numerical': 0.12139423076923077, 'mean_word_length': 5.694369973190349, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '520065', 'license': 'MIT', 'n_tokens_mistral': 1045, 'n_tokens_neox': 828, 'n_words': 210, 'path': 'notebooks/arules2.ipynb', 'repo_name': 'eacunafer/Data-Mining-Machine-Learning-subgraduado-', 'size': '2501'}