<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Krupaashah on Medium]]></title>
        <description><![CDATA[Stories by Krupaashah on Medium]]></description>
        <link>https://medium.com/@krupaashah2006?source=rss-1bb42077d309------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Krupaashah on Medium</title>
            <link>https://medium.com/@krupaashah2006?source=rss-1bb42077d309------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 14:13:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@krupaashah2006/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Inside the Basket: How Data Learns Associations]]></title>
            <link>https://medium.com/@krupaashah2006/inside-the-basket-how-data-learns-associations-c26928e209b7?source=rss-1bb42077d309------2</link>
            <guid isPermaLink="false">https://medium.com/p/c26928e209b7</guid>
            <category><![CDATA[association-rule]]></category>
            <dc:creator><![CDATA[Krupaashah]]></dc:creator>
            <pubDate>Fri, 30 Jan 2026 16:01:58 GMT</pubDate>
            <atom:updated>2026-01-30T16:01:58.089Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>What are Association Rules?</strong></h3><p>Association Rules are a type of unsupervised machine learning technique wherein the data does not have predefined labels or outputs. Association Rules is a data mining technique aiming to discover relationships between different constraints. It solely works on the input given and aims to discover the hidden relationships within the data. So, the Association Rules are if-then statements that show the probability of relationships between the features of the data given. So, what do we mean by these if-then statements? Let’s take an example, there is a probability that 60% of customers who buy clothing will also buy accessories. Here, we recognize an association between clothing and accessories, and this itself is the association rule. Association rules are widely used in the real-world applications to analyze the user navigation patterns such as recommendation systems used in Netflix, Amazon, etc. One of the most common applications is the market basket analysis. It is mostly used by the retailers to understand the requirements of the customers and thus design better product placements and discounts. Apart from these applications, association rules are also used in healthcare for disease and symptom analysis.</p><h3><strong>Some of the key terms involved</strong></h3><p>Association Rules are represented as:</p><p><strong>X </strong>→ <strong>Y</strong></p><p>Where X is called the Antecedent,</p><p>Y is called the Consequent</p><p>X, that is the antecedent, represents the items that we know are bought by the customers. Y, on the other hand, represents the items that we predict to be purchased by the customers. Basically, X and Y are disjoint sets. According to the Association Rule, if an item appears in set X, it tends to appear in set Y also. X is the “if” part in the association rule, and Y is the “then” part. Let’s head to some of the metrics required for evaluating Association rules.</p><p><strong>Support:</strong></p><p>A transaction is a complete set of items or events that occurred at a particular time. It is a measure of how frequently an item appears or an event occurs in the dataset. It is calculated by dividing the number of transactions containing both X and Y by the total number of transactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*rgy0k9ytTGTS6zqr3p0jAA.png" /></figure><p>· <strong>Confidence:</strong></p><p>It measures the strength of the association between the two items X and Y. It is calculated by dividing the number of transactions containing both the items by the number of transactions having only the first item that is X.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*fZ46PnlJUwvTa2LgM2Zwag.png" /></figure><p>· <strong>Lift:</strong></p><p>It is used to compare the strength of the association between the two items X and Y with the expected strength of the association if the two items were independent. It is calculated by dividing the confidence by the support of the second item that is Y. If the value of lift is greater than 1, it indicates a positive association that means the items occur more than expected, if it is equal to 1, it indicates an independent relationship between the two. If the value is less than 1, it implies a negative association.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*LnKN6W3KyjmNLNFRttxh0A.png" /></figure><p>Let’s take an example to understand these terminologies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*U0MhVJxcqJ2TXZfG64DJiQ.png" /></figure><p>Let the association rule be:</p><p><strong><em>{T-shirt, Footwear} </em></strong>→<strong><em> {Jewellery}</em></strong></p><p>Calculating support, confidence and lift:</p><p>· <strong>Support = (2/5) = 0.4</strong></p><p>· <strong>Confidence = (2/3) = 0.67</strong></p><p>Because T-shirt and Footwear appear together in 3 transactions.</p><p>· <strong>Lift = ((2/3)/(4/5)) = 0.83</strong></p><h3><strong>Algorithms involved in Association Rules</strong></h3><p>Despite being very powerful, Association rules have some limitations. It may happen that they generate a large number of rules but many of them are insignificant. Choosing appropriate threshold values is also very challenging as low values may result in too many rules, while high values may miss important patterns.</p><p>Coming to the algorithms used in the Association Rules, they include the Apriori algorithm, Eclat algorithm, and the FP growth algorithm. Firstly, the Apriori algorithm is used when working with smaller datasets. Eclat algorithm should be used when our priority is speed and better memory management. FP growth algorithm is used when our datasets are huge. Each of these algorithms follows a different strategy for frequent itemset generation and is suitable for different types of datasets.</p><h3><strong>Implementation of Apriori Algorithm:</strong></h3><p><a href="https://medium.com/@krupaashah2006/from-transactions-to-trends-the-apriori-algorithm-36075a3e6488">https://medium.com/@krupaashah2006/from-transactions-to-trends-the-apriori-algorithm-36075a3e6488</a></p><h3><strong>Implementation of Eclat Algorithm:</strong></h3><p><a href="https://medium.com/@krupaashah2006/mining-smarter-understanding-the-eclat-algorithm-338166d37c74">https://medium.com/@krupaashah2006/mining-smarter-understanding-the-eclat-algorithm-338166d37c74</a></p><h3><strong>Implementation of FP Growth Algorithm:</strong></h3><p><a href="https://medium.com/@krupaashah2006/optimizing-pattern-discovery-the-fp-growth-approach-92396964dc33">https://medium.com/@krupaashah2006/optimizing-pattern-discovery-the-fp-growth-approach-92396964dc33</a></p><h3><strong>Resources:</strong></h3><p><a href="https://kaumadiechamalka100.medium.com/apriori-algorithm-examples-be8915b01cf2">https://kaumadiechamalka100.medium.com/apriori-algorithm-examples-be8915b01cf2</a></p><p><a href="https://medium.com/data-science/the-fp-growth-algorithm-1ffa20e839b8">https://medium.com/data-science/the-fp-growth-algorithm-1ffa20e839b8</a></p><p><a href="https://www.geeksforgeeks.org/machine-learning/association-rule/">https://www.geeksforgeeks.org/machine-learning/association-rule/</a></p><p><a href="https://www.analyticsvidhya.com/blog/2021/10/a-comprehensive-guide-on-market-basket-analysis/">https://www.analyticsvidhya.com/blog/2021/10/a-comprehensive-guide-on-market-basket-analysis/</a></p><p><a href="https://www.geeksforgeeks.org/machine-learning/apriori-algorithm/">https://www.geeksforgeeks.org/machine-learning/apriori-algorithm/</a></p><p><a href="https://www.geeksforgeeks.org/machine-learning/frequent-pattern-growth-algorithm/">https://www.geeksforgeeks.org/machine-learning/frequent-pattern-growth-algorithm/</a></p><p><a href="https://www.geeksforgeeks.org/machine-learning/ml-eclat-algorithm/">https://www.geeksforgeeks.org/machine-learning/ml-eclat-algorithm/</a></p><p><a href="https://www.geeksforgeeks.org/machine-learning/frequent-pattern-growth-algorithm/">https://www.geeksforgeeks.org/machine-learning/frequent-pattern-growth-algorithm/</a></p><p><a href="https://iaviral.medium.com/what-is-eclat-algorithm-e3ed949c1cf">https://iaviral.medium.com/what-is-eclat-algorithm-e3ed949c1cf</a></p><p><a href="https://www.datacamp.com/tutorial/association-rule-mining-python">https://www.datacamp.com/tutorial/association-rule-mining-python</a></p><p><a href="https://thinkingneuron.com/how-to-do-association-rule-mining-using-fp-growth-in-python/%20">https://thinkingneuron.com/how-to-do-association-rule-mining-using-fp-growth-in-python/</a></p><p><a href="https://www.geeksforgeeks.org/machine-learning/frequent-pattern-growth-algorithm/">https://www.geeksforgeeks.org/machine-learning/frequent-pattern-growth-algorithm/</a></p><p><a href="https://iaviral.medium.com/what-is-eclat-algorithm-e3ed949c1cf">https://iaviral.medium.com/what-is-eclat-algorithm-e3ed949c1cf</a></p><p><a href="https://medium.com/@rithpansanga/association-rule-mining-apriori-eclat-fp-growth-4a6e1c4c9b3e">https://medium.com/@rithpansanga/association-rule-mining-apriori-eclat-fp-growth-4a6e1c4c9b3e</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c26928e209b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing Pattern Discovery: The FP-Growth Approach]]></title>
            <link>https://medium.com/@krupaashah2006/optimizing-pattern-discovery-the-fp-growth-approach-92396964dc33?source=rss-1bb42077d309------2</link>
            <guid isPermaLink="false">https://medium.com/p/92396964dc33</guid>
            <category><![CDATA[fp-growth]]></category>
            <category><![CDATA[association-rule]]></category>
            <dc:creator><![CDATA[Krupaashah]]></dc:creator>
            <pubDate>Fri, 30 Jan 2026 15:51:18 GMT</pubDate>
            <atom:updated>2026-01-30T15:51:18.946Z</atom:updated>
            <content:encoded><![CDATA[<p>The FP Growth Algorithm is commonly viewed as the modern version of the Apriori Algorithm as it is more efficient and faster. It is extensively used in “Frequent Itemset Mining” and “Basket Analysis”. Frequent Itemset Mining is used to find the product combinations that are often bought together. Basket Analysis is used to study products that are frequently bought together.</p><h3><strong>Steps that are followed in the FP Growth Algorithm:</strong></h3><p><strong>i.</strong> <strong>Counting the frequency of each item in the dataset and applying the Minimum Support rule:</strong></p><p>The FP Growth algorithm too starts by calculating the frequency of each item in the dataset. It then uses the minimum support rule and discards all the items from the dataset that do not meet the minimum support.</p><p><strong>ii.</strong> <strong>Removing the items that did not meet the minimum support and creating an ordered table:</strong></p><p>After completing Step 1, we now create the same table but without the items that did not meet the minimum support rule. This table will contain the values that have not been rejected yet and arranged in ordered table.</p><p><strong>iii.</strong> <strong>Creating a tree:</strong><br> Now we create a tree with the first item, that is, the most frequent as the first node in the tree. Each product will be a node in the tree with the highest frequency item as the root node. We continue adding the elements in the tree until the tree is complete. Once done, we see that it is faster to traverse and find the data items with the most frequency.</p><p><strong>Let’s take an example to understand this.</strong></p><p>We have the following transaction IDs along with the items purchased.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*1yEON73w-fNvCfKy8Ri8WQ.png" /></figure><p><strong>Step 1:</strong></p><p>Here, we count the frequency of each data item.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*bhuQbZF8c2VedEX-xfeIkw.png" /></figure><p>Let’s say we have our minimum support = 5.</p><p>Thus, backpack, sunglasses, jacket and cap will be discarded.</p><p><strong>Steps 2:</strong></p><p>Now, we create a new ordered table without backpack, sunglasses, jacket and cap.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*6vd7xqInjSOWuHw9OH5BdA.png" /></figure><p><strong>Step 3:<br> </strong>Now, we start creating a tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*ZECv0LOg2OdLrqj7vE4gnQ.png" /></figure><p>Since, T-shirt has the highest frequency, our first node will be the T-shirt.</p><p><strong>Starting off with the first transaction.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*Wkp7uUQm7fDqVxYM0IcguA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*coJISDP_9QXqO-0GIF0jQg.png" /></figure><p>Thus, tree created:<br> T-shirt → Footwear → Food-item</p><p><strong>For transaction 2:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*xYQ9QZhqS7NzydHFr5uKxg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*1gr76F3R1f2NWqB1X7MVSA.png" /></figure><p>Thus, tree created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*t6zT8L5xo3p1NEyEoUXt-g.png" /></figure><p>Jeans is the branch of Footwear.</p><p><strong>For transaction 3:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*Ej4pnKGgCxgqywdIi2WQGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*y8VM2FI6-xGC5EZgyZm5HQ.png" /></figure><p>Thus, tree created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*2iV9yGGcbfURmF_pdP4mUg.png" /></figure><p>Here, food item is the branch of T-shirt.</p><p>Similarly, we complete all transactions and get the tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*iJA1pubi9UlXBiLJMJtrAQ.png" /></figure><p>With this, we get the final tree of the FP growth algorithm.</p><p><strong>Implementing FP Growth Algorithm in Python</strong></p><p><strong>Step 1: Downloading the required libraries</strong></p><pre>!pip install pandas mlxtend</pre><p>We install the required libraries for data handling.</p><p><strong>Step 2: Importing the libraries</strong></p><pre>import pandas as pd<br>from mlxtend.preprocessing import TransactionEncoder<br>from mlxtend.frequent_patterns import fpgrowth, association_rules</pre><p><strong>Step 3: Loading the dataset</strong></p><pre>from google.colab import drive<br>drive.mount(&#39;/content/drive&#39;)<br>file_path = &quot;/content/drive/MyDrive/market_basket.csv.xlsx&quot;<br>dataset = pd.read_excel(file_path)<br>dataset.head()</pre><p>(Here’s the link for the dataset used — <a href="https://docs.google.com/spreadsheets/d/1_M3UDxNixqtM7XfwfW-b3hTTHNXvbiX4/edit?usp=sharing&amp;ouid=108760572907719397295&amp;rtpof=true&amp;sd=true">Dataset</a> )</p><p><strong>Step 4: Data Preprocessing</strong></p><pre>df_items = dataset.drop(columns=[&#39;TransactionID&#39;])<br>transactions = []<br>for i in range(len(df_items)):<br>transactions.append([str(item) for item in df_items.iloc[i].dropna()])<br>te = TransactionEncoder()<br>te_array = te.fit(transactions).transform(transactions)<br>df_encoded = pd.DataFrame(te_array, columns=te.columns_)<br>df_encoded</pre><p>Output is seen as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*MoIU5PIxb9-CWeNkKyTIrg.png" /></figure><p>So, for the Apriori Algorithm we require the data to be in the form:</p><p>Transaction 1 → [Milk, beer, diaper]</p><p>Transaction 2 → [Beer, diaper]</p><p>So, we convert each row into a list of items and perform one-hot encoding.</p><p>Thus, we get a table like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*kRVj7IHZLvwnQZLtcPqJ8Q.png" /></figure><p>This is also called transaction encoding.</p><p><strong>Step 5: Apply the apriori algorithm</strong></p><pre>frequent_itemsets = fpgrowth(df_encoded, min_support=0.1, use_colnames=True)<br>frequent_itemsets</pre><p>On executing we get,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*lcVp8wr6zmhFQbK3zEupsw.png" /></figure><p>Here, the actual algorithm starts. This step finds frequent itemsets. It keeps only those transactions that appear in atleast 10% of all transactions. It calculates support that is, how often they appear.</p><p>Thus, from the output we can see</p><p>Beer → Support = 0.36</p><p>Bread, Milk → Support = 0.56</p><p>This means Beer appears in 36% of the transactions, and the combination Bread and Milk appears together in 56% of the transactions.</p><p><strong>Step 6: Generate Association Rules</strong></p><pre>rules = association_rules(frequent_itemsets, metric=&quot;confidence&quot;, min_threshold=0.6)<br>rules[[&#39;antecedents&#39;, &#39;consequents&#39;, &#39;support&#39;, &#39;confidence&#39;, &#39;lift&#39;]]</pre><p>Output is seen as,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*iWguPcS2ozS8ZddmukrNeA.png" /></figure><p>This step creates: If a customer buys butter, then customer buys bread.</p><p>It measures the antecedents and consequents by:</p><p>· Support: How often both items appear</p><p>· Confidence: Probability of buying bread if the customer buys beer</p><p>· Lift: Strength of the relationship.</p><p>So, let’s take the relationship butter →bread</p><p>Lift = 1.07. Thus, customers who buy butter are 1.07 times more likely to buy bread than a random chance.</p><p><strong>Step 7: Filter the stronger association rules</strong></p><pre>rules.sort_values(by=&quot;lift&quot;, ascending=False).head(10)</pre><p>Finally, we get,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y2XoOK9WwxCiwa1kW8UAwg.png" /></figure><p>This step helps us to generate the rules that are most powerful and meaningful. We sort all the values in descending order of the value of lift. This gives us the top 10 most likely if-then relations.</p><p>Although the FP-Growth algorithm works by constructing an FP-Tree, when using libraries like mlxtend, <strong>the tree is built internally </strong>and is not explicitly displayed. The frequent itemsets are directly extracted from this FP-Tree and returned as output.</p><p><strong>Conclusion</strong></p><p>FP-Growth is best used when dealing with large transactional datasets where fast and efficient frequent itemset mining is required. It is especially suitable for dense datasets in market basket analysis, recommendation systems, and retail analytics, where transactions contain many items and traditional algorithms like Apriori become slow due to repeated database scans and large candidate generation. Although the construction and traversal of FP-Tree is complex, consumes more memory due to tree structure, harder to visualize and interpret compared to Apriori and not ideal for very sparse datasets, the FP Growth is a powerful and scalable choice for frequent pattern mining when performance is a critical requirement.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92396964dc33" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mining Smarter: Understanding the ECLAT Algorithm]]></title>
            <link>https://medium.com/@krupaashah2006/mining-smarter-understanding-the-eclat-algorithm-338166d37c74?source=rss-1bb42077d309------2</link>
            <guid isPermaLink="false">https://medium.com/p/338166d37c74</guid>
            <category><![CDATA[eclat]]></category>
            <category><![CDATA[association-rule]]></category>
            <dc:creator><![CDATA[Krupaashah]]></dc:creator>
            <pubDate>Thu, 29 Jan 2026 12:56:31 GMT</pubDate>
            <atom:updated>2026-01-29T12:56:31.687Z</atom:updated>
            <content:encoded><![CDATA[<p>The Eclat algorithm is used in the Association Rules technique to find combinations of items that frequently appear together in transactions. Unlike Apriori, which uses a horizontal layout, Eclat works on a vertical layout and computes frequent itemsets using intersection of transaction ID sets (tidsets), making it more efficient for dense datasets.</p><h3><strong>Steps that are followed in the Eclat Algorithm:</strong></h3><p><strong>i.</strong> <strong>Converting the dataset into a vertical format and calculating the support of each item:</strong></p><p>The Eclat algorithm starts by calculating the frequency, that is, for a particular item how many transaction IDs are applicable for the given the dataset. We create a tidset which is simply a set of transaction IDs where the item appears. Further, it also discards the items from the dataset that do not meet the minimum support. In simple words, the minimum support rule is a number that tells us how often the items should appear in the dataset. Further, it discards all the items from the dataset that do not meet the minimum support.</p><p><strong>ii.</strong> <strong>Calculate the support of item sets by intersecting the tidsets:</strong></p><p>After completing Step 1, with the residue tidsets, the algorithm combines them into groups of size 2, 3, and so on. Then it again uses the minimum support rule and discards the sets that do not meet the threshold value of the support. This process is repeated again and again by forming groups of 3, 4, etc. till it reaches a point where it cannot create more sets.</p><p><strong>iii.</strong> <strong>Eclat property:</strong></p><p>Similar to the Apriori property, Eclat also follows its property, that is, if an itemset is infrequent then all of its supersets will also be infrequent. This means that if the intersection of two tidsets does not satisfy the minimum support, then there is no need to extend this itemset further, as any larger combination containing it will also be infrequent. This property helps in pruning the search space and makes the algorithm efficient.</p><p>Let’s take an example to understand this algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*O8uWFU0u9a84kmvlYLZEVQ.png" /></figure><p>Assume the minimum support threshold is 2 (i.e., an itemset must appear in at least 2 transactions to be considered frequent).</p><p><strong>Step 1:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*2sM1XzgWdwr7zo6MwoMb-w.png" /></figure><p><strong>Step 2:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*po6mSzWHECk0iZYTqUNVYQ.png" /></figure><p>Since the itemset (Food-item, footwear) has a support of 1, it is discarded and is considered infrequent as our minimum support = 2. Therefore, it will not be extended further to form larger itemsets.</p><p><strong>Step 3:</strong></p><p>After obtaining the frequent itemsets, association rules are generated using confidence and lift measures. Confidence represents the probability of purchasing the consequent given the antecedent, while lift indicates the strength of the relationship between the items.</p><p>Finally, we get association rule like: {T-shirt, Footwear} {Food item}</p><p>This rule means that customers who buy T-shirt and Footwear are likely to also buy Food items. Such rules are useful for recommendation systems and product placement strategies in retail stores.</p><p>Thus, the Eclat algorithm efficiently discovers frequent itemsets using vertical data format and tidset intersections, making it faster than Apriori for dense datasets and suitable for large transactional databases.</p><h3><strong>Implementation of ECLAT Algorithm in Python</strong></h3><p><strong>Step 1: Downloading the required libraries</strong></p><pre>!pip install pandas pyECLAT</pre><p><strong>Step 2: Importing the libraries</strong></p><pre>import pandas as pd<br>from pyECLAT import ECLAT<br>import warnings<br>warnings.filterwarnings(&quot;ignore&quot;)</pre><p><strong>Step 3: Loading the dataset</strong></p><pre>from google.colab import drive<br>drive.mount(&#39;/content/drive&#39;)<br>file_path = &quot;/content/drive/MyDrive/market_basket.csv.xlsx&quot;<br>df = pd.read_excel(file_path)<br>df.head()</pre><p>(Here’s the link for the dataset used — <a href="https://docs.google.com/spreadsheets/d/1_M3UDxNixqtM7XfwfW-b3hTTHNXvbiX4/edit?gid=1599641610#gid=1599641610">Dataset</a>)</p><p><strong>Step 4: Data Pre-processing (Vertical Format)</strong></p><pre>df_items = df.drop(columns=[&#39;TransactionID&#39;])<br>df_items.columns = range(df_items.shape[1])<br>df_items.head()</pre><p>Before applying the Eclat algorithm, the raw transaction data must be converted into a format that the algorithm can understand and process efficiently.</p><p>Here, we are dropping the TransactionID column as it is not required for transaction mining.</p><p>We also rename the renaming to indices 0, 1, 2, 3, etc.</p><p>The data after pre-processing now looks like</p><p>Bread — {1, 2, 4, 5, 7, 9, …}</p><p>Milk — {1, 3, 4, 5, 6, 9, …}</p><p>Butter — {1, 6, 10, 11, …}</p><p>Beer — {2, 3, 8, 14, 18, …}</p><p>Diapers — {2, 3, 4, 5, 8, 18, …}</p><p><strong>Step 5: Apply the ECLAT Algorithm</strong></p><pre>eclat = ECLAT(data=df_items, verbose=True)<br>frequent_itemsets, support = eclat.fit(<br>min_support=0.03,<br>min_combination=1,<br>max_combination=3<br>)</pre><p>Here, the actual algorithm starts. This step finds frequent item transactions. It keeps only those transactions that appear in atleast 3% of all transactions. It calculates support that is, how often they appear.</p><p><strong>Step 6: Convert Frequent Itemsets to DataFrame</strong></p><pre>support_df = pd.DataFrame({<br>&#39;Itemset&#39;: list(support.keys()),<br>&#39;Support&#39;: list(support.values())<br>})<br>support_df.sort_values(by=&#39;Support&#39;, ascending=False).head()</pre><p>On executing, we something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*aNOPWBVTrw6f8E-JXLKynw.png" /></figure><p>This converts the ECLAT output into a table with two columns:</p><ul><li><strong>Itemset</strong> → the item combinations</li><li><strong>Support</strong> → how frequently they appear</li></ul><p><strong>Step 7: Generate Association Rules</strong></p><pre>from mlxtend.frequent_patterns import association_rules<br>support_df[&#39;itemsets&#39;] = support_df[&#39;Itemset&#39;].apply(lambda x: frozenset(x.split(&#39; &amp; &#39;)))<br>support_df[&#39;support&#39;] = support_df[&#39;Support&#39;]<br>support_df = support_df[[&#39;itemsets&#39;, &#39;support&#39;]]<br>rules = association_rules(support_df, metric=&quot;confidence&quot;, min_threshold=0.3)<br>rules[[&#39;antecedents&#39;, &#39;consequents&#39;, &#39;support&#39;, &#39;confidence&#39;, &#39;lift&#39;]]</pre><p>Output is seen as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*I1X2E8s077xGzsxDbMR-Qg.png" /></figure><p>This converts itemset strings like “Bread &amp; Milk” into sets: {Bread, Milk}. Then, we keep only the columns needed for generating, that is, itemsets and their support.</p><p><strong>Step 8: Filter the Strongest Association Rules</strong></p><pre>rules[[&#39;antecedents&#39;, &#39;consequents&#39;, &#39;support&#39;, &#39;confidence&#39;, &#39;lift&#39;]] \<br>.sort_values(by=&#39;lift&#39;, ascending=False) \<br>.head(10)</pre><p>We get something as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*g2AP6pRbfISeFb49d9_viQ.png" /></figure><p>This takes only the columns: antecedents, consequents, support, confidence, lift. Then, we sort all rules by lift in descending order (strongest first) showing the top 10 strongest association rules</p><h3><strong>Conclusion</strong></h3><p>The Eclat algorithm is an efficient technique for finding and concluding frequent itemsets. It is faster than the Apriori algorithm. Also, it requires fewer database scans, thus faster. ECLAT is best suited for datasets where transactions contain many items (dense data) and where fast computation of frequent itemsets is required. It is particularly useful in market basket analysis, recommendation systems, and retail analytics when the dataset size is manageable and memory is sufficient.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=338166d37c74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Transactions to Trends: The Apriori Algorithm]]></title>
            <link>https://medium.com/@krupaashah2006/from-transactions-to-trends-the-apriori-algorithm-36075a3e6488?source=rss-1bb42077d309------2</link>
            <guid isPermaLink="false">https://medium.com/p/36075a3e6488</guid>
            <category><![CDATA[apriori]]></category>
            <category><![CDATA[apriori-algorithm]]></category>
            <category><![CDATA[association-rule]]></category>
            <dc:creator><![CDATA[Krupaashah]]></dc:creator>
            <pubDate>Thu, 29 Jan 2026 12:39:15 GMT</pubDate>
            <atom:updated>2026-01-29T12:39:15.803Z</atom:updated>
            <content:encoded><![CDATA[<p>The Apriori algorithm is very popular and well-known mainly because of its simplicity and straight-forwardness. Apriori reduces the search space significantly by pruning infrequent itemsets early, making it efficient for small to medium-sized datasets.</p><h3><strong>Steps that are followed in the Apriori Algorithm:</strong></h3><p><strong>i.</strong> <strong>Counting the frequency of each item in the dataset and applying the Minimum Support rule:</strong></p><p>The Apriori algorithm starts by calculating the frequency of each item in the dataset. These are called 1-item sets. It now uses a rule called minimum support. In simple words, it is a number that tells us how often the items should appear in the dataset. Further, it discards all the items from the dataset that do not meet the minimum support.</p><p><strong>ii.</strong> <strong>Creating Item groups:</strong></p><p>After completing Step 1, with the residue 1-item sets, the algorithm combines them into groups of 2 called the 2-item sets. Then it again uses the minimum support rule and discards the sets that do not meet the threshold value of the support. This process is repeated iteratively by forming groups of size 3, 4, and so on, until no further frequent itemsets can be generated.</p><p><strong>iii.</strong> <strong>Removing the infrequent groups:</strong></p><p>Now, the algorithm removes the infrequent groups simultaneously using the Apriori Property. According to this property, if a particular group does not appear frequent then its larger group is also infrequent and thus it discards that particular group. If an itemset is infrequent, all its supersets are also infrequent.</p><p>Let’s take an example to understand this algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*eLRuPbjrO7Ev-wA-JFD6Gw.png" /></figure><p><strong>Step 1:</strong></p><ul><li><strong>T-shirt</strong> → appears in transactions 1, 2, 3 → <strong>frequency = 3</strong></li><li><strong>Footwear</strong> → appears in transactions 1, 2 → <strong>frequency = 2</strong></li><li><strong>Food item</strong> → appears in transactions 1, 3 → <strong>frequency = 2</strong></li></ul><p><strong>Step 2:</strong></p><p>Combine them into sets of 2 like {T-shirt, Footwear}, {Food item, Footwear}, and {T-shirt, Food item}. Filter out the ones that don’t meet the minimum support required. Continue the same with sets of 3.</p><p><strong>Step 3:</strong></p><p>Finally, we get association rule like: {T-shirt, Footwear} → {Food item}</p><p>This rule is generated after filtering frequent itemsets using minimum support and confidence thresholds.</p><h3><strong>Implementation of Apriori Algorithm in Python</strong></h3><p><strong>Step 1: Downloading the required libraries</strong></p><pre>pip install mlxten</pre><p><strong>Step 2: Importing the libraries</strong></p><pre>import pandas as pd<br>from mlxtend.preprocessing import TransactionEncoder<br>from mlxtend.frequent_patterns import apriori, association_rules</pre><p><strong>Step 3: Loading the dataset</strong></p><pre>from google.colab import drive<br>drive.mount(&#39;/content/drive&#39;)<br>file_path = &#39;/content/drive/MyDrive/market_basket.csv.xlsx&#39;<br>df = pd.read_excel(file_path)<br>df.head()</pre><p>(Here’s the link for the dataset used <a href="https://docs.google.com/spreadsheets/d/1_M3UDxNixqtM7XfwfW-b3hTTHNXvbiX4/edit?usp=sharing&amp;ouid=108760572907719397295&amp;rtpof=true&amp;sd=true">— Dataset</a> )</p><p><strong>Step 4: Data Preprocessing</strong></p><pre>transactions = []<br>for i in range(len(df)):<br>transactions.append([str(item) for item in df.iloc[i].dropna().tolist()])<br>te = TransactionEncoder()<br>te_array = te.fit(transactions).transform(transactions)<br>df_encoded = pd.DataFrame(te_array, columns=te.columns_)</pre><p>So, for the Apriori Algorithm we require the data to be in the form:</p><p>Transaction 1 → [Milk, beer, diaper]</p><p>Transaction 2 → [Beer, diaper]</p><p>So, we convert each row into a list of items and perform one-hot encoding.</p><p>Thus, we get a table like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/1*rwiFcp_Rn7kmJ-avXLQLaA.png" /></figure><p>This is also called transaction encoding.</p><p><strong>Step 5: Apply the apriori algorithm</strong></p><pre>frequent_itemsets = apriori(df_encoded, min_support=0.03, use_colnames=True)<br>frequent_itemsets</pre><p>We see the output as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*iZuetAxNHgMUzpHHQ1Ga2Q.png" /></figure><p>Here, the actual algorithm starts. This step finds frequent item transactions. It keeps only those transactions that appear in atleast 3% of all transactions. It calculates support, that is, how often they appear.</p><p>Thus, from the output we can see</p><p>Beer → Support = 0.36</p><p>Milk, Coke, Diapers → Support = 0.06</p><p><strong>Step 6: Generate Association Rules</strong></p><pre>rules = association_rules(frequent_itemsets, metric=&quot;confidence&quot;, min_threshold=0.6)<br>rules[[&#39;antecedents&#39;, &#39;consequents&#39;, &#39;support&#39;, &#39;confidence&#39;, &#39;lift&#39;]]</pre><p>On executing we get,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*BpMimoU2ilER5qSazFel6A.png" /></figure><p>This step creates: If a customer buys beer, then the customer buys bread.</p><p>It measures the antecedents and consequents by:</p><p>· Support: How often both items appear</p><p>· Confidence: Probability of buying bread if the customer buys beer</p><p>· Lift: Strength of the relationship.</p><p>So, let’s take the relationship chips → beer</p><p>Lift = 1.85. Thus, customers who buy chips are 1.85 times more likely to buy beer than a random chance.</p><p><strong>Step 7: Filter the stronger association rules</strong></p><pre>rules.sort_values(by=&quot;lift&quot;, ascending=False).head(10)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*wJgSdl4GcW4spgbmtKH05w.png" /></figure><p>This step helps us to generate the rules that are most powerful and meaningful. We sort all the values in descending order of the value of lift. This gives us the top 10 most likely if-then relations.</p><p><strong>Conclusion</strong></p><p>The Apriori algorithm is one of the most widely used for association rule mining. It works by generating itemsets that appear frequently in the dataset and removing the ones that are insignificant. The datasets are removed if its support is less than the minimum support used. It is best used when the dataset is small. It is commonly applied in market basket analysis, educational demonstrations, and situations where computational resources are limited.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36075a3e6488" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>