0% found this document useful (0 votes)
9 views

MLT

The document outlines the implementation of the Apriori and FP-Growth algorithms for analyzing customer purchase patterns in a supermarket. It details the steps for loading transaction data, finding frequent item sets, and generating association rules using Python in Rapidminer. The objective is to optimize product placement and run targeted promotions based on identified patterns of frequently bought products.

Uploaded by

gnanalahari07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

MLT

The document outlines the implementation of the Apriori and FP-Growth algorithms for analyzing customer purchase patterns in a supermarket. It details the steps for loading transaction data, finding frequent item sets, and generating association rules using Python in Rapidminer. The objective is to optimize product placement and run targeted promotions based on identified patterns of frequently bought products.

Uploaded by

gnanalahari07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

TASK- 4

Implement Apriori and FP-growth algorithm to find all frequent item sets for the chosen dataset and
also generate Association Rules.

Platform: Rapidminer, Language: Python

Use Case: Supermarket Purchase Analysis

Objective:

A supermarket wants to analyze customer purchase patterns to optimize product placement and run
targeted promotions. The goal is to identify frequent item sets and association rules among purchased
products.

Implementation:

The supermarket has a transaction history that includes the items purchased by customers. Using the FB
Growth algorithm and association rule mining, the supermarket aims to discover patterns of products
that are frequently bought together.

FP-Growth:

Algorithm:

Step 1: Load Dataset

Click ->Import-> select from My computer and load, Save under Local Repository

Step 2: Set positive values true to positive.

Step 3: Add FB growth and set support value.

Step 4: View the frequency item set.

Step 5: At create association and set the confidence value.

Step 6: View both rules and item set.

Step 7: Execute the model.

Apriori

Algorithm:

from mlxtend.frequent_patterns import apriori

from mlxtend.frequent_patterns import association_rules


import pandas as pd

# Step 1: Input transaction data

transactions = [

['A', 'B', 'C'],

['A', 'C', 'D'],

['B', 'C', 'D'],

['A', 'D', 'E'],

['B', 'C', 'E']

# Convert to a DataFrame of 0/1 (one-hot encoded)

data = pd.DataFrame([

{'A': 'A' in t, 'B': 'B' in t, 'C': 'C' in t, 'D': 'D' in t, 'E': 'E' in t}

for t in transactions

])

# Step 2: Find frequent itemsets with a minimum support of 0.4

frequent_itemsets = apriori(data, min_support=0.4, use_colnames=True)

# Step 3: Generate association rules with a minimum confidence of 0.6

rules = association_rules(frequent_itemsets, metric="confidence", min_threshold=0.6)

# Display results

print("Frequent Itemsets:")

print(frequent_itemsets)

print("\nAssociation Rules:")

print(rules)

Result:

Thus the FP-Growth and Apriori algorithm to find all frequent item sets were implemented successfully.

You might also like