<?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 Harsh on Medium]]></title>
        <description><![CDATA[Stories by Harsh on Medium]]></description>
        <link>https://medium.com/@hgupta604?source=rss-ad18c86d85f8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*ecYJHAw1RCR6GP281O43Dw.jpeg</url>
            <title>Stories by Harsh on Medium</title>
            <link>https://medium.com/@hgupta604?source=rss-ad18c86d85f8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 20:12:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hgupta604/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[Classifying Fashion_Mnist dataset with Convolutional Neural Nets.]]></title>
            <link>https://medium.com/swlh/classifying-fashion-mnist-dataset-with-convolutional-neural-nets-dd092d755164?source=rss-ad18c86d85f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd092d755164</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[fashion]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[fashion-mnist]]></category>
            <dc:creator><![CDATA[Harsh]]></dc:creator>
            <pubDate>Wed, 18 Mar 2020 18:43:23 GMT</pubDate>
            <atom:updated>2020-03-21T19:41:29.304Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="CNN overview" src="https://cdn-images-1.medium.com/max/469/1*dYSThYBVtfyIIa2puCi6Tw.png" /><figcaption>Overview of techniques involved in CNN</figcaption></figure><p>Congratulations!! You made it this far. I promise that i won’t bore you with fancy technical lexicons and jargons. Let’s dive into <strong>CNN</strong>.</p><blockquote>Convolutional Neural Network, generally abbreviated as ConvNet or simply CNN, is the most ubiquitous form of neural network used to work with image data.</blockquote><p>As the name suggests, CNN literally makes use of convolutional layers, albeit with a combination of pooling and activation layers, to reduce the size of input and extract salient features from image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*BJhsRMRGkLt3_d32j6-Bcw.png" /><figcaption>images in the fashion_mnist dataset</figcaption></figure><p>In my opinion, the f<a href="https://www.tensorflow.org/datasets/catalog/fashion_mnist">ashion_mnist</a> dataset is a great tool for beginners to work with. The dataset contains 10 target classes labeled from 0 to 10 each representing an article of clothing. Each target class has an associated 28x28 grayscale image of the article of clothing.</p><p>Let’s begin. For starters, we need to download the dataset and explore</p><pre>from keras.datasets import fashion_mnist</pre><pre>(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()</pre><pre>print(&#39;Shape:&#39;)<br>print(&#39;X_Train {}&#39;.format(x_train.shape))<br>print(&#39;Y_Train {}&#39;.format(y_train.shape))<br>print(&#39;X_Test {}&#39;.format(x_test.shape))<br>print(&#39;Y_Test {}&#39;.format(y_test.shape))</pre><pre>output:<br><strong>Shape:<br>X_Train (60000, 28, 28)<br>Y_Train (60000,)<br>X_Test (10000, 28, 28)<br>Y_Test (10000,)</strong></pre><p>Oh yes, the data is already divided in training and test dataset. Keras wants you to waste no time in preprocessing and start making Neural Net Models right away. But wait, this is a categorization problem. We need to categorize the piece of clothing as one label out of the ten labels. This makes it important to check if the categories are balanced in both the training and test dataset.</p><pre><strong>def check_samples(sample, plot=True):</strong><br>    counter = {}<br>    for key in sample:<br>        if key not in counter.keys():<br>            counter[key] = 1<br>        else:<br>            counter[key] = counter[key] + 1<br>    df_dict = {&#39;cat&#39;:[x for x in counter.keys()], &#39;cnt&#39;:[y for y in            counter.values()]}<br>    cnt_df = pd.DataFrame(df_dict)<br>    if plot:<br>        sns.barplot(data=cnt_df, x=&#39;cat&#39;, y=&#39;cnt&#39;)<br>        plt.xlabel(&#39;Category&#39;)<br>        plt.ylabel(&#39;Count&#39;)<br>        plt.title(&#39;# of Obs. in each Category&#39;)<br>        return None<br>    else:<br>    return cnt_df</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*QzXsJeTUDxFhKiNLHkon0A.png" /></figure><p>All the categories have equal number of observations. The dataset is balanced.</p><p><strong>This part is experimental.</strong></p><p>Working with the data, i realized that the images have no noise and are straight grayscale images. To make my model more versatile, i performed basic geometric transformations and produced a larger dataset with scaled, translated and normalized images. The dataset now is increased in size and contains original images along with it’s transformed self. To avoid creation of ‘pockets’ — rows in dataset with similar data spatially close to each other — I shuffled the dataset.</p><pre>#Scale Image<br><strong>def scale_img(dim, img):</strong><br>    resized_img = cv2.resize(np.asarray(img), dim, interpolation = cv2.INTER_AREA)<br>    return resized_img</pre><pre>#Normalize Image<br><strong>def normalize_img(img, is_gray = False):</strong><br>    normalized_img = cv2.normalize(img, img, 0, 255, cv2.NORM_MINMAX)<br>    if is_gray:<br>        cvt = cv2.cvtColor(normalized_img, cv2.COLOR_BGR2GRAY)<br>        return cvt<br>    return normalized_img</pre><pre>#Rotate Image<br><strong>def rotate_img(img, rot_deg):</strong><br>    rows,cols = img.shape[0], img.shape[1]<br>    M = cv2.getRotationMatrix2D((cols/2,rows/2),rot_deg,1)<br>    dst = cv2.warpAffine(img,M,(cols,rows))<br>    return dst</pre><pre>#Translate Image<br><strong>def translate_img(img,x=100,y=50):</strong><br>    rows,cols = img.shape[0], img.shape[1]<br>    M = np.float32([[1,0,x],[0,1,y]])<br>    dst = cv2.warpAffine(img,M,(cols,rows))<br>    return dst</pre><pre>x_train_tran = x_train.tolist()<br>y_train_tran = y_train.tolist()<br>ctr = 0<br>for img in x_train:<br>    x_train_tran.append(rotate_img(img, 90))<br>    y_train_tran.append(y_train[ctr])<br>    x_train_tran. append(translate_img(img, x=15, y=15))<br>    y_train_tran.append(y_train[ctr])<br>    ctr = ctr + 1</pre><pre>x_train_tran = np.array(x_train_tran).reshape(len(x_train_tran), 28, 28, 1)<br>y_train_tran = to_categorical(np.array(y_train_tran))</pre><pre>x_train_tran, y_train_tran = shuffle(x_train_tran, y_train_tran)</pre><pre>print(&#39;Shape:&#39;)<br>print(&#39;X_Train {}&#39;.format(x_train_tran.shape))<br>print(&#39;Y_Train {}&#39;.format(y_train_tran.shape))</pre><pre>Output:<br><strong>Shape:<br>X_Train (180000, 28, 28, 1)<br>Y_Train (180000, 10)</strong></pre><p>Here are some sample images in the dataset</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*tPK-bhNdd_4SwNuR5Uy_SQ.png" /><figcaption>Augmented Dataset with Transformed Images</figcaption></figure><h3>Time to create CNN Model.</h3><p>I played with quite a few models. Training each model takes a lot of time. This is the simplest and effective model.</p><pre>cnn_model = Sequential()<br>cnn_model.add(Conv2D(filters=128, kernel_size=(5,5), activation=&#39;relu&#39;,input_shape=(28,28,1)))<br>cnn_model.add(MaxPooling2D(pool_size=(3,3), strides=(3,3)))<br>cnn_model.add(Conv2D(filters=64, kernel_size=(2,2), activation=&#39;relu&#39;))<br>cnn_model.add(MaxPooling2D(pool_size=(2,2)))<br>cnn_model.add(Conv2D(filters=32, kernel_size=(2,2), activation=&#39;relu&#39;))<br>cnn_model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2)))<br>cnn_model.add(Flatten())<br>cnn_model.add(Dense(32, activation=&#39;relu&#39;))<br>cnn_model.add(Dense(to_categorical(y_train).shape[1], activation=&#39;softmax&#39;))</pre><p>The model smartly named cnn_model, as if it was not apparent, is the most standard version of CNN. It is a sequential model. Believe me sequential models are simple and easy to play with than a functional model.</p><pre>&gt;&gt; cnn_model.summary()</pre><pre><strong>Output:</strong></pre><pre>Model: &quot;sequential_1&quot;<br>_________________________________________________________________<br>Layer (type)                 Output Shape              Param #   <br>=================================================================<br>conv2d_3 (Conv2D)            (None, 24, 24, 128)       3328      <br>_________________________________________________________________<br>max_pooling2d_3 (MaxPooling2 (None, 8, 8, 128)         0         <br>_________________________________________________________________<br>conv2d_4 (Conv2D)            (None, 7, 7, 64)          32832     <br>_________________________________________________________________<br>max_pooling2d_4 (MaxPooling2 (None, 3, 3, 64)          0         <br>_________________________________________________________________<br>conv2d_5 (Conv2D)            (None, 2, 2, 32)          8224      <br>_________________________________________________________________<br>max_pooling2d_5 (MaxPooling2 (None, 1, 1, 32)          0         <br>_________________________________________________________________<br>flatten_1 (Flatten)          (None, 32)                0         <br>_________________________________________________________________<br>dense_2 (Dense)              (None, 32)                1056      <br>_________________________________________________________________<br>dense_3 (Dense)              (None, 10)                330       <br>=================================================================<br>Total params: 45,770<br>Trainable params: 45,770<br>Non-trainable params: 0<br>_________________________________________________________________</pre><p>The model has 3 convolutional (conv2D) layers each of which separated by a max pooling layer. Each conv layer has a different kernel size and a different number of filters that helps to create a feature map. MaxPooling helps to reduce the size of the feature map making it easy to work with. There are various options in Pooling (max, min and avg). The one i used is a maxpooling layer as i need to keep the pixels with maximum value.</p><p>Each conv layer uses filters to extract the important details from the image. The filter is a matrix (generally a smaller matrix than the matrix of the original image) with values which is superimposed on the 28x28 matrix of the image and is slid across the original matrix to produce a resultant matrix called feature map which is usually the cartesian product of the filter and the original matrix and captures different features from image. For example, the filters below used by 2nd conv layer helped in detecting curve like pattern in the image as shown in the feature maps below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*zOOMUu9uVUOXyaS5aYOgFw.png" /><figcaption>Filter matrices of 2nd hidden convolutional layer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*q9EY0jPfWfkAYmO6F_Vbyg.png" /><figcaption>Feature Maps of 2nd hidden convolutional layer.</figcaption></figure><h3>Running the model.</h3><pre>es = EarlyStopping(monitor=&#39;loss&#39;, min_delta=1e-4, patience=15, verbose=2, mode=&#39;auto&#39;)</pre><pre>cnn_model.compile(optimizer=&#39;adam&#39;, loss=&#39;categorical_crossentropy&#39;, metrics=[&#39;accuracy&#39;])</pre><pre>cnn_model.fit(x_train_tran, y_train_tran, batch_size=32, epochs=150, callbacks=[es])</pre><p>Classifying test data.</p><pre>preds = cnn_model.predict(x_test_tran)</pre><pre>pred_list = []<br>for i in preds:<br>    pred_list.append(np.argmax(i))</pre><pre><br>from sklearn.metrics import accuracy_score</pre><pre>print(&#39;{}%&#39;.format(accuracy_score(y_pred=pred_list,y_true=y_test) * 100))<br><strong>Output<br>91.1%</strong></pre><h3>Visualizing Results</h3><p>Finding number of observations classified for each class versus how many really exists in that class. This will help us know how is the model performing for each class. If the model is biased towards one class, it will classify more number of observations as that class.</p><pre>class_map = {0:&#39;T-shirt/top&#39;,<br>             1:&#39;Trouser&#39;,<br>             2:&#39;Pullover&#39;,<br>             3:&#39;Dress&#39;,<br>             4:&#39;Coat&#39;,<br>             5:&#39;Sandal&#39;,<br>             6:&#39;Shirt&#39;,<br>             7:&#39;Sneaker&#39;,<br>             8:&#39;Bag&#39;,<br>             9:&#39;Ankle boot&#39;}</pre><pre>true_class_ct = {}<br>for i in range(10):<br>    true_class_ct[class_map[i]] = sum(1 for x in incorrect_df[&#39;true&#39;] if x == class_map[i])</pre><pre>pred_class_ct = {}<br>for i in range(10):<br>    pred_class_ct[class_map[i]] = sum(1 for x in incorrect_df[&#39;pred&#39;] if x == class_map[i])<br>pred_class_ct</pre><pre>op = {}<br><strong>def percentage_error(trueval, changedval, i):</strong><br>    op[class_map[i]] = ((changedval - trueval)/trueval) * 100</pre><pre>for ct in range(10):<br>    tv = true_class_ct[class_map[ct]]<br>    cv = pred_class_ct[class_map[ct]]<br>    percentage_error(tv, cv, ct)<br>    <br>fig, ax = plt.subplots()<br>width = 0.4<br>x = np.arange(10)<br>rects1 = ax.bar(x - width/2, list(true_class_ct.values()), width, label=&#39;True&#39;)<br>rects2 = ax.bar(x + width/2, list(pred_class_ct.values()), width, label=&#39;CNN Predicted&#39;)<br>ax.set_ylabel(&#39;Count&#39;)<br>ax.set_title(&#39;Classification Error in each class&#39;)<br>ax.set_xticks(x)<br>ax.set_xticklabels(list(op.keys()))<br>ax.legend()<br>plt.xticks(rotation=45)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*hcbDVSo75AGPFtgSMInzQA.png" /></figure><p>We can also view percentage of classification error in each class</p><pre>sns.barplot(x=list(op.keys()), y=list(op.values()))<br>plt.ylabel(&quot;Percentage&quot;)<br>plt.title(&#39;Percentage error for each class&#39;)<br>plt.xticks(rotation=45)<br>plt.xlabel(&#39;Classes&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*5jOViXacVXEPce9P6zXTVg.png" /></figure><p>Sneakers seems to be a problem. The model classified 60% more samples as sneakers than the original samples that were sneakers. Percentage, however, by itself is not enough. If we consider both bar charts, we can see that our model is overfitting few categories. There are few ways to avoid that.</p><ol><li>Regularization (L1/L2)</li><li>Adding Dropout Layers</li><li>Adding more data by data augmentation (which we did).</li></ol><p>Model fitting in my opinion is an iterative process. You begin with a model that you think has best hyperparameters to understand data. You then assess the model to see how well it performs on the training data using metrics like accuracy, loss etc. If the model seems to be not doing great, you tweak the hyperparameters and fit the model again until you reach a desired model. Hypothetically, a desired model is the one that has close to 100% accuracy and, that does not over or under-fit on training set and is not biased.</p><p><strong>Best of luck on your AI journey!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd092d755164" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/classifying-fashion-mnist-dataset-with-convolutional-neural-nets-dd092d755164">Classifying Fashion_Mnist dataset with Convolutional Neural Nets.</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Association Analysis in Python]]></title>
            <link>https://medium.com/analytics-vidhya/association-analysis-in-python-2b955d0180c?source=rss-ad18c86d85f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b955d0180c</guid>
            <category><![CDATA[association-analysis]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[frequent-itemset-mining]]></category>
            <category><![CDATA[apriori]]></category>
            <dc:creator><![CDATA[Harsh]]></dc:creator>
            <pubDate>Thu, 26 Sep 2019 07:51:21 GMT</pubDate>
            <atom:updated>2021-06-26T23:49:14.493Z</atom:updated>
            <content:encoded><![CDATA[<h4>Frequent Item set Mining using Apriori algorithm in Python</h4><p>This document is written for individuals who have prior knowledge of Apriori and its working.</p><p>To refresh apriori, straight from Wikipedia:</p><blockquote><strong><em>Apriori</em></strong><em> is an </em><a href="https://en.wikipedia.org/wiki/Algorithm"><em>algorithm</em></a><em> for frequent item set mining and </em><a href="https://en.wikipedia.org/wiki/Association_rule_learning"><em>association rule learning</em></a><em> over relational </em><a href="https://en.wikipedia.org/wiki/Databases"><em>databases</em></a><em>. It proceeds by identifying the frequent individual items in the database and extending them to larger and larger item sets as long as those item sets appear sufficiently often in the database. The frequent item sets determined by Apriori can be used to determine </em><a href="https://en.wikipedia.org/wiki/Association_rules"><em>association rules</em></a><em> which highlight general trends in the </em><a href="https://en.wikipedia.org/wiki/Database"><em>database</em></a><em>: this has applications in domains such as </em><a href="https://en.wikipedia.org/wiki/Market_basket_analysis"><em>market basket analysis</em></a><em>.</em></blockquote><blockquote><em>-Apriori Algorithm</em>, <em>Wikipedia 2019.</em></blockquote><p>Apriori algorithm is the perfect algorithm to start with association analysis as it is not just easy to understand and interpret but also to implement.</p><p>Python has many libraries for apriori implementation. One can also implement the algorithm from scratch. But wait, there is mlxtend for the rescue. This library has beautiful implementation of apriori and it also allows to extract association rules from the result.</p><p>So what are we waiting for? Let’s start coding!!</p><p>We will make use of the following python libraries<br>1. Remember good ol’ pandas and numpy?<br>2. mlxtend or ML extended will be used for apriori implementation and extracting association rules.<br>3. And then there was one: matplotlib for visualizing results</p><pre>import pandas as pd<br>import numpy as np<br>from mlxtend.frequent_patterns import apriori, association_rules<br>import matplotlib.pyplot as plt</pre><blockquote>The dataset I chose for this purpose is a custom dataset that I created. If you wish to play with the dataset, you can find it <a href="https://gist.github.com/Harsh-Git-Hub/2979ec48043928ad9033d8469928e751">here</a>.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/deffc9fb37c82b82605f768e462f9250/href">https://medium.com/media/deffc9fb37c82b82605f768e462f9250/href</a></iframe><pre>## Use this to read data directly from github<br>df = pd.read_csv(&#39;<a href="https://gist.githubusercontent.com/Harsh-Git-Hub/2979ec48043928ad9033d8469928e751/raw/72de943e040b8bd0d087624b154d41b2ba9d9b60/retail_dataset.csv&#39;">https://gist.githubusercontent.com/Harsh-Git-Hub/2979ec48043928ad9033d8469928e751/raw/72de943e040b8bd0d087624b154d41b2ba9d9b60/retail_dataset.csv&#39;</a>, sep=&#39;,&#39;)</pre><pre>## Use this to read data from the csv file on local system.<br>df = pd.read_csv(&#39;./data/retail_data.csv&#39;, sep=&#39;,&#39;) </pre><pre>## Print first 10 rows <br>df.head(10)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gNksc7JYVXB2n6pIZzG8Eg.png" /></figure><p>Each row of the dataset represents items that were purchased together on the same day at the same store.The dataset is a <strong>sparse dataset</strong> as relatively high percentage of data is NA or NaN or equivalent.</p><p>These NaNs make it hard to read the table. Let’s find out how many unique items are actually there in the table.</p><pre>items = set()<br>for col in df:<br>    items.update(df[col].unique())</pre><pre>print(items)</pre><pre>Out:<br>{&#39;Bread&#39;, &#39;Cheese&#39;, &#39;Meat&#39;, &#39;Eggs&#39;, &#39;Wine&#39;, &#39;Bagel&#39;, &#39;Pencil&#39;,<br>       &#39;Diaper&#39;, &#39;Milk&#39;]}</pre><p>There are only 9 items in total that make up the entire dataset. Nice, easier to find frequent itemset or so you think!!</p><h3>Data Preprocessing</h3><p>To make use of the apriori module given by mlxtend library, we need to convert the dataset according to it’s liking. apriori module requires a dataframe that has either 0 and 1 or True and False as data. The data we have is all string (name of items), we need to <strong>One Hot Encode</strong> the data.</p><p>Custom One Hot Encoding</p><pre>itemset = set(items)<br>encoded_vals = []<br>for index, row in df.iterrows():<br>    rowset = set(row) <br>    labels = {}<br>    uncommons = list(itemset - rowset)<br>    commons = list(itemset.intersection(rowset))<br>    for uc in uncommons:<br>        labels[uc] = 0<br>    for com in commons:<br>        labels[com] = 1<br>    encoded_vals.append(labels)<br>encoded_vals[0]</pre><pre>ohe_df = pd.DataFrame(encoded_vals)</pre><h3>Applying Apriori</h3><p>apriori module from mlxtend library provides fast and efficient apriori implementation.</p><blockquote><strong><em>apriori(df, min_support=0.5, use_colnames=False, max_len=None, verbose=0, low_memory=False)</em></strong></blockquote><p>Parameters</p><ul><li>df : One-Hot-Encoded DataFrame or DataFrame that has 0 and 1 or True and False as values</li><li>min_support : Floating point value between 0 and 1 that indicates the minimum support required for an itemset to be selected.<br># of observation with item / total observation# of observation with item / total observation</li><li>use_colnames : This allows to preserve column names for itemset making it more readable.</li><li>max_len : Max length of itemset generated. If not set, all possible lengths are evaluated.</li><li>verbose : Shows the number of iterations if &gt;= 1 and low_memory is True. If =1 and low_memory is False , shows the number of combinations.</li><li>low_memory :</li><li>If True, uses an iterator to search for combinations above min_support. Note that while low_memory=True should only be used for large dataset if memory resources are limited, because this implementation is approx. 3–6x slower than the default.</li></ul><pre>freq_items = apriori(ohe_df, min_support=0.2, use_colnames=True, verbose=1)<br>freq_items.head(7)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*GTwIS1NQ8FoFXYGH6oq_UA.png" /></figure><p>The output is a data frame with the support for each itemsets.</p><h3>Mining Association Rules</h3><p>Frequent if-then <strong>associations</strong> called <strong>association rules</strong> which consists of an antecedent (if) and a consequent (then).</p><blockquote><strong><em>association_rules(df, metric=’confidence’, min_threshold=0.8, support_only=False)</em></strong></blockquote><p>Metric can be set to confidence, lift, support, leverage and conviction.</p><pre>rules = association_rules(freq_items, metric=&quot;confidence&quot;, min_threshold=0.6)<br>rules.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JhKQHhTkyAhVy1XxKFJMbw.png" /></figure><p>The result of association analysis shows which item is frequently purchased with other items.</p><h3>Visualizing results</h3><ol><li><strong>Support vs Confidence</strong></li></ol><pre>plt.scatter(rules[&#39;support&#39;], rules[&#39;confidence&#39;], alpha=0.5)<br>plt.xlabel(&#39;support&#39;)<br>plt.ylabel(&#39;confidence&#39;)<br>plt.title(&#39;Support vs Confidence&#39;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*o-uDGp3IqxW1BTV4Etnz7A.png" /></figure><p>2. <strong>Support vs Lift</strong></p><pre>plt.scatter(rules[‘support’], rules[‘lift’], alpha=0.5)<br>plt.xlabel(‘support’)<br>plt.ylabel(‘lift’)<br>plt.title(‘Support vs Lift’)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*mZEVDMIXmtZEJRKYc-YpSw.png" /></figure><p><strong>Lift vs Confidence</strong></p><pre>fit = np.polyfit(rules[‘lift’], rules[‘confidence’], 1)<br>fit_fn = np.poly1d(fit)<br>plt.plot(rules[‘lift’], rules[‘confidence’], ‘yo’, rules[‘lift’], <br> fit_fn(rules[‘lift’]))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*vRaM0i1FQDrOAndoITW9rw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b955d0180c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/association-analysis-in-python-2b955d0180c">Association Analysis in Python</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>