Question

Write a Python Program to implement the Apriori algorithmona dataset of your own choice.

 

 

17 Feb 2026
Answer :
Word Count : 659
The Apriori algorithm is a classical algorithm in data mining used for mining frequent itemsets and generating association rules from transactional datasets. It works on the principle that any subset of a frequent itemset must also be frequent. This property, known as the Apriori property, helps in pruning the search space significantly. In an AI and Machine Learning Lab, implementing Apriori in Python helps students understand unsupervised learning concepts, pattern discovery, support counting, and candidate generation. Below is a Python program that implements the Apriori algorithm on a sample transactional dataset of a small grocery store. The dataset consists of transactions where each transaction contains a list of items purchased together. The program identifies frequent itemsets based on a minimum support threshold and then generates association rules based on a minimum confidence threshold. ```python # Apriori Algorithm Implementation in Python from itertools import combinations # Sample transactional dataset (Grocery Store) dataset = [ ['Milk', 'Bread', 'Butter'], ['Beer', 'Bread'], ['Milk', 'Bread', 'Butter', 'Beer'], ['Bread', 'Butter'], ['Milk', 'Butter'], ['Beer', 'Bread'], ['Milk', 'Bread', 'Beer', 'Butter'] ] def get_support(itemset, transactions): count = 0 for transaction in transactions: if set(itemset).issubset(set(transaction)): count += 1 return count / len(transactions) def generate_candidates(prev_frequent, k): candidates = [] prev_frequent_list = list(prev_frequent) for i in range(len(prev_frequent_list)): for j in range(i + 1, len(prev_frequent_list)): union_set = prev_frequent_list[i].union(prev_frequent_list[j]) if len(union_set) == k: candidates.append(union_set) return list(set(candidates)) def apriori(transactions, min_support): items = set() for transaction in transactions: for item in transaction: items.add(frozenset([item])) frequent_itemsets = {} current_frequent = set() # Generate 1-itemsets for item in items: support = get_support(item, transactions) if support >=
________ _________ ____ _____ __________ ______.
____ _______ __________ ______ _____ _________.
________ _________ _______ ____ _______ __________ ____ ________.
____ ________ ___ ______ _____ ___ _____.
_______ ___ _____ _______ __________ __________ _________.
____ ________ __________ _________ _____ ________ __________ _____ _________.
_________ _____ ___ _________ _________ _________ __________ ______ ______.
__________ _________ ____ ____ _________ _________ _____ ___ _______ ___ _________ _________.
_________ _____ _________ __________ _______ ________ _________.
______ ______ __________ _____ _______ ______ ______.
_______ _____ _______ ________ __________ __________ ________ _________.
____ ________ _______ ___ ________ ____ __________.
______ ___ _____ _________ ____ ___ _______ ______.
_______ _________ _______ ___ ______ _________ ___.
________ ________ _____ ______ ______ _________ ____ ___ _________ _________.
________ ____ ____ _______ _________ __________ __________ ______ ___ ____ ______.
__________ ___ ________ ____ ___ ______ ___ ________ _____ ________ _____ __________.
_____ _______ _________ _____ ______.
___ ______ ______ _________ _________ _________.
__________ ________ __________ _____ _________ ___ _________ ______ _____.
___ __________ _______ _____ ________ __________ ______ _______.
_______ _____ __________ ____ ___ ______ __________ ___.
_______ ______ ____ ____ _____ _______ _______ ___ ____ ___ _____.
____ ______ ___ ______ ______ ______ ___ ________ _______ _____ _________.
____ __________ _____ ____ __________ ____ ______.
_______ ___ _____ _________ ____ ______ ________.
__________ __________ _________ ____ ____ ______ ____ _________ __________ ______ ________ ________.
____ ___ _____ _______ ____ ____ ________.
_________ ___ __________ ______ ______ ______.
____ _____ __________ ________ _____ _______ ______.
_____ ___ ______ _____ _________ ________ ____ ________ ________ __________.
________ ________ _________ ____ ____ _____.
____ _______ _________ _______ _________ ________.
______ _____ _________ _____ ________ __________ _________ __________.
___ ______ ____ _________ ____.
______ _____ _____ ___ __________ ________.
____ ________ __________ ___ ___ ___ ______ _________ ______ ________.
__________ ________ ____ _______ ______ _____ _________.
___ _______ _________ ______ ______ ____.
______ ___ ____ _________ ___ __________ _____ ________ __________ _________.
______ __________ _____ ______ ______ ___.
____ __________ ______ ____ _____.
_______ _________ _____ _______ __________ ______ ___ ____ ___ ______ ___.
____ ________ __________ __________ _______ _____.
______ _____ ___ ______ ____ ________ ___ __________ ______ _________ _______ _________.
__________ _________ ___ __________ _____.
____ ___ ______ __________ _________.
__________ ___ ______ ___ ______ ___ __________ ________ ______.
____ ___ ______ _______ _________ _____ __________ ___ ________ _________.
_______ ___ __________ ____ ________ ______ ______ _________ _____.
_______ _______ __________ _____ ______.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU MCSL 228 2026 - Write a Python Program to implement the Apriori algorithmona dataset o | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→