Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to make association rules for grocery items using apriori algorithm in python?

Description

To implement apriori algorithm for grocery items in python.

Input

Grocery data.

Output

Association between the items.

Process

  Import the library.

  Load the data set.

  Build the model.

  Fit the grocery data.

  Make the association rules.

  Print the rules.

Sample Code

#import the library
import numpy as np
import pandas as pd
from apyori import apriori

#load the data
store_data = pd.read_csv(‘……/grocery.csv’)

#initialize a empty list
records = []
for i in range(0, 19):
records.append([str(store_data.values[i,j]) for j in range(0, 4)])

#applying apirori
association_rules = apriori(records, min_support=0.03, min_confidence=0.2, min_lift=3, min_length=2)

#make it as a data frame
df = pd.DataFrame(association_rules)

#create a excel file for results
final = df.to_excel(‘…/asso_rules.xlsx’)

for i in range(0,16):
print(df.loc[i])

Screenshots
make association rules for grocery items using apriori algorithm in python
import pandas as pd