<?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 Dan Isaza on Medium]]></title>
        <description><![CDATA[Stories by Dan Isaza on Medium]]></description>
        <link>https://medium.com/@daniel.isaza.93?source=rss-e5aea0e80a38------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0nuqc9XyMFEksETOgDPRhQ.jpeg</url>
            <title>Stories by Dan Isaza on Medium</title>
            <link>https://medium.com/@daniel.isaza.93?source=rss-e5aea0e80a38------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 07:51:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@daniel.isaza.93/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[We’re Hiring Two Full-Stack Engineers]]></title>
            <link>https://medium.com/@daniel.isaza.93/were-hiring-two-full-stack-engineers-273292ada5fb?source=rss-e5aea0e80a38------2</link>
            <guid isPermaLink="false">https://medium.com/p/273292ada5fb</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[hiring]]></category>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[remote]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Dan Isaza]]></dc:creator>
            <pubDate>Tue, 05 May 2020 02:20:32 GMT</pubDate>
            <atom:updated>2020-05-05T02:20:32.653Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi there 👋🏽</p><p>My name is Dan Isaza, and I’m the VP of Engineering at Clever Real Estate.</p><p>Our Engineering team is hiring two Fullstack Engineers.</p><p>Below, I’ll share a few things about the company and the position.</p><p>If you’re interested, please reach out to me: <a href="/service/mailto:dan@movewithclever.com">dan@movewithclever.com</a></p><h3>How does Clever make money?</h3><p>We connect customers to real estate agents and help them save money in the process (sellers get a discount on commission, buyers get a rebate on their home purchase). When a customer buys/sells a home, we get a percentage of the real estate agent’s revenue in exchange for having sent them the customer.</p><h3>What makes Clever unique? (What is defensible?)</h3><p>Our “secret sauce” has two parts and is centered around providing a seamless customer experience.</p><p><strong>Our Secret Sauce Recipe</strong></p><ul><li>Our in-house Concierge Team provides a seamless customer experience that our competitors simply don’t have.</li><li>Our proprietary technology allows our Concierge Team to provide this seamless experience at scale.</li></ul><p>In that way, we’re a lot like StitchFix. They have amazing stylists, and they have lots of tech and automation behind the scenes that allows them to scale the experience. We’re kind of like StitchFix, but for finding real estate agents.</p><h3>The Concierge Team</h3><p>Before being matched with agents, customers talk to folks on the Concierge Team. These folks are a resource for answering customer questions about real estate and setting expectations about the home buying / selling process.</p><p>There’s a lot of regulation about what can and cannot be said to customers about real estate (especially around commissions), so each concierge has to become a licensed real estate agent themselves. There’s no way around it: that’s a lot of work. We do it, and our competitors don’t. As a result, we can provide a much better experience to our customers.</p><h3>The Technology: Our proprietary Agent Matching Platform (AMP⚡)</h3><p>We believe that every homeowner’s situation is unique and deserves the attention of a trained and caring concierge. We also believe in the power of technology to augment our team’s abilities.</p><p>With our Agent Matching Platform (or AMP) at their sides, our Concierge Team can quickly and easily navigate thousands of data points about the 8K real estate agents on our platform.</p><p>The goal is not to automate the Concierge experience, but rather: to scale it through the use of technology.</p><p>Our customers love our Concierge Team, and the AMP allows lets us deliver this high-touch experience to thousands of customers with a relatively small in-house team.</p><h3>What is Clever’s current financial position? How have we prepared for COVID?</h3><p>We believe in transparency and regularly discuss this question with our team (every 6 weeks). We go over: <em>How much money is in the bank? How much do we make each month? How much do we spend?</em></p><p>I’ll hold off on posting more details in this public post, but I’m happy to share more details over the phone, including specific steps we took to prepare for COVID and the effect that it’s had on our revenue.</p><h3>How has COVID affected home sales?</h3><p>We talk to our customers and agents regularly to get a sense for this.</p><p>Here’s what we’re seeing:</p><ul><li>Folks meet with their real estate agents over zoom</li><li>Buyers use video walkthroughs or 3d-tours (where available) to whittle down the list of houses they’re interested in</li><li>In-person showings are only done if folks are very serious about buying. Showings are private (rather than in big groups), and folks keep a distance / wear masks.</li></ul><p>In addition to this, we believe that any longer-term market downturn will encourage consumers to seek out savings. We offer some of the largest savings in the industry and believe that this will be a big advantage if there is a long-term economic downturn.</p><h3>What are your values?</h3><p>We are a highly collaborative team that values pair-programming, learning sessions, and end-to-end ownership of initiatives.</p><p>We value learning together. We regularly teach each other new things through Learning Sessions.</p><p>We believe that engineering is a team sport. We all participate in DevOps, and we strive to eliminate “single points of failure” by sharing context. We don’t like “hero ball”; instead, we prefer to tackle problems together.</p><p>We have a culture of blame-free continuous improvement.</p><p>Here’s an excerpt from our Blameless Post-Mortem template:</p><p>(Much of this wording is taken directly from <a href="https://www.amazon.com/DevOps-Handbook-World-Class-Reliability-Organizations/dp/1942788002">The Devops Handbook</a>)</p><blockquote><em>Remember: We’re trying to prepare for a future where we’re as humanly fallible as we are today. It’s not productive for us to come out of this meeting with a decision to “be less stupid” or “be more careful”. Rather, we should try to identify fool-proof countermeasures that we can use to avoid issues in the future. This may involve an automated system or a documented process that captures organizational learning.</em></blockquote><blockquote><em>We should explicitly disallow the phrases “would have” and “could have”. It’s much more productive to think about </em>why<em> we chose a course of action and what we’ll do in the future to improve our incident prevention and response practices.</em></blockquote><blockquote><em>Finally, remember that this meeting is not about naming, blaming, or shaming others. It’s about improving ourselves as a team.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8WHnOPPBljsFW7gmAQHNdg.jpeg" /><figcaption>We help people find amazing homes, like this one!</figcaption></figure><h3>What’s the current state of the Engineering team?</h3><p>The whole team is currently four people (myself included). Two folks build and maintain our customer-facing website. Two people (myself included) build and maintains the AMP.</p><p>We’re looking for two more people to join us in building the AMP.</p><p>Our engineers take ownership of creating their own technical specs, and they collaborate a lot with each other and with product stakeholders. As a small team, we have a lot of personal ownership over the planning process.</p><p>We regularly reflect on what’s working and what’s not, and we adjust our processes accordingly.</p><p>Oh, also: we’re remote! Each engineer is in a different location, and all company meetings are done remote-first. (i.e. everyone on their own laptop, even if they’re sitting in the same office).</p><p>The total company size is 25 people, with about half of those in our HQ office in St. Louis. The rest are remote. 😄</p><h3>What are you hiring for? Looking for?</h3><p>We’re looking for a full-stack contributor to help us continue building and maintaining our Agent Matching Platform.</p><p>We are looking for someone who values collaboration and has strong communication skills.</p><p>Our ideal engineer is someone who enjoys pair programming, thinking through decisions together, and breaking down problems to solve them iteratively.</p><p>If you have experience with Django and/or React, that’s great! If not, that’s okay.</p><p>Our onboarding process involves a lot of pairing, so we’ll get you up to speed on our tech stack.</p><p>We’re interested in mid-level or senior engineers.</p><p>If you or someone you know might be a fit, please reach out! 😄</p><p>You can reach me at:<br><a href="/service/mailto:dan@movewithclever.com">dan@movewithclever.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=273292ada5fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Further Exploration of Association Rules]]></title>
            <link>https://medium.com/weekly-data-science/independent-itemsets-interest-proof-23265dd9abd6?source=rss-e5aea0e80a38------2</link>
            <guid isPermaLink="false">https://medium.com/p/23265dd9abd6</guid>
            <category><![CDATA[math]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-mining]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Dan Isaza]]></dc:creator>
            <pubDate>Thu, 19 Jul 2018 00:09:31 GMT</pubDate>
            <atom:updated>2018-07-19T00:12:13.394Z</atom:updated>
            <content:encoded><![CDATA[<p>Here, we’ll take a quick look at why an association rule between two itemsets that appear in baskets with independent probabilities has an expected <em>interest</em> of zero. (As a shorthand, we can call these independent itemsets.)</p><p>I’ll assume that you’ve read <a href="https://medium.com/weekly-data-science/finding-meaningful-associations-in-retail-data-6ababd031171">Finding Meaningful Associations in Retail Data</a> — which pairs well with <a href="https://medium.com/weekly-data-science/the-intuition-behind-the-apriori-algorithm-4efe312ccc3c">The Intuition Behind the Apriori Algorithm</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZDndmjWNP4UvGjTkJnRMug.jpeg" /><figcaption><a href="https://unsplash.com/photos/el5RpIy4o5c">https://unsplash.com/photos/el5RpIy4o5c</a></figcaption></figure><h4>Vocabulary Recap</h4><p>If you’ve read the <a href="https://medium.com/weekly-data-science/the-intuition-behind-the-apriori-algorithm-4efe312ccc3c">Apriori</a> and <a href="https://medium.com/weekly-data-science/finding-meaningful-associations-in-retail-data-6ababd031171">Meaningful Associations</a> posts, these terms will be familiar.</p><ul><li>Our dataset consists of shopping carts at time of checkout. We call these <em>baskets. </em>They consist of items. Groups of items are called <em>itemsets</em>.</li><li>The number of baskets that an itemset appears in is called the <em>support</em> of that itemset. An itemset is <em>frequent</em> if it’s support above some predefined <em>support threshold</em>.</li><li>An <em>association rule</em> takes the form I → j, where I is an itemset and j is a single item. For example, <em>{bread, eggs} → flour</em> is an association rule. Describing this association rule allows us to say how purchasing bread and eggs influences purchasing flour, if at all.</li><li><em>Confidence</em> is a useful intermediary metric when discussing association rules, though it doesn’t mean much by itself. <em>Interest</em>, however, is quite meaningful. If you haven’t encountered these terms before, you really should read <a href="https://medium.com/weekly-data-science/finding-meaningful-associations-in-retail-data-6ababd031171">Finding Meaningful Associations in Retail Data</a>.</li></ul><h4>Quick note on Notation</h4><p>Let’s distinguish between <em>Pr.(j)</em> and <em>P(j)</em>. Let <em>Pr.(j)</em> represent the proportion of baskets in which <em>j</em> appears, whereas <em>P(j)</em> is the true probability of observing <em>j</em> in a basket.</p><blockquote>Pr.(j) = Support(j) / (Num. Baskets) = the proportion of baskets containing j</blockquote><blockquote>P(j) = True probability of observing j in a basket.</blockquote><p>Note that <em>P(j) = E[Pr.(j)]</em>, but this doesn’t mean that <em>Pr.(j)</em> and <em>P(j)</em> are always equal.</p><p>Let <em>I</em> be an itemset and <em>j</em> be an item, both of which appear in a retail dataset with <em>N</em> baskets, and let observing <em>I</em> and <em>j </em>in a basket be independent events.</p><p>Assume, for the sake of contradiction, that the association rule <em>I → j</em> has an expected interest that is not zero.</p><p>Begin by taking the expectation of the definition of <em>interest</em> and expand by substituting the definition of <em>confidence</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wTmu1NsmH0CNxnwX1i-3Rg.png" /></figure><p>Multiplying the confidence term by (1/N)/(1/N) yields:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*op7ytbd2WBdkK8juGRr6TQ.png" /><figcaption>Note that we’re just multiplying one of the terms by 1.</figcaption></figure><p>Note that the terms in the numerator and denominator become Pr.(I and j) and Pr.(I), respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yFAk2dxPronfKB0T2gB8xg.png" /><figcaption>Note the change from set notation to probability notation.</figcaption></figure><p><strong>Keep in mind: </strong>We’re moving from set notation to probability notation here, so I’ve chosen to use words rather than symbols to denote “and”, so as to avoid confusion.</p><p>We then apply the <a href="https://en.wikipedia.org/wiki/Expected_value#Linearity">linearity of expectation</a> to get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U8XCx5kuyrJrvtuP6iHjOA.png" /></figure><p>Recall that the expected proportion of baskets in which <em>I</em> and <em>j</em> occur is equal to the true probability of observing both <em>I</em> and <em>j</em> in a basket. The same is true for the proportion of baskets that contain <em>I</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fq_FJA6PI7sV7K55pe7-4A.png" /><figcaption>Now we’re using the true probabilities of observing these itemsets.</figcaption></figure><p>Note that since observing <em>I</em> and observing <em>j</em> are independent events, we can express <em>P(I and j)</em> as <em>P(I)P(j)</em>. (They are independent events, so we multiply them to get the probability of them both occurring.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OQxK3rQpNXvnKTDtBBlH4Q.png" /><figcaption>Observing I and observing j are independent events.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iU-6tA9QeBYhpHd_ODubog.png" /></figure><p>Note that we’ve shown that the expected interest of the association rule I → j is zero. This directly contradicts our assumption that observing I and j are independent events and that the E[Interest(I → j)] ≠0. Thus, it is not possible that observing I and j be independent events and that E[Interest(I → j)] ≠ 0, proving that E[Interest(I → j)] = 0 when observing I and j are independent events. (Q.E.D.)</p><p>So there we have it — a quick proof on why the expected interest of an association rule is zero when observing the two itemsets involved are independent events.</p><p><em>Want to see more posts like this? Consider hitting the Follow button.</em></p><p><em>Share your thoughts in the comments below!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23265dd9abd6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-data-science/independent-itemsets-interest-proof-23265dd9abd6">Further Exploration of Association Rules</a> was originally published in <a href="https://medium.com/weekly-data-science">Weekly Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The PCY Algorithm and Its Friends]]></title>
            <link>https://medium.com/weekly-data-science/the-pcy-algorithm-and-its-friends-ecba67216190?source=rss-e5aea0e80a38------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecba67216190</guid>
            <category><![CDATA[data-mining]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Dan Isaza]]></dc:creator>
            <pubDate>Sat, 30 Jun 2018 03:52:32 GMT</pubDate>
            <atom:updated>2018-07-19T06:28:21.655Z</atom:updated>
            <content:encoded><![CDATA[<p>In previous posts, I’ve covered the <a href="https://medium.com/weekly-data-science/the-intuition-behind-the-apriori-algorithm-4efe312ccc3c">Apriori Algorithm</a> and <a href="https://medium.com/weekly-data-science/hash-functions-for-data-mining-55e9c7760703">hash functions in the context of data mining</a>. If you’re unfamiliar with those concepts, I recommend taking a moment to read up on them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r0sMHpeCKaWHizf_GgZkgg.jpeg" /><figcaption><a href="https://unsplash.com/photos/AWYI4-h3VnM">https://unsplash.com/photos/AWYI4-h3VnM</a></figcaption></figure><p>The Apriori Algorithm finds frequent itemsets by making several passes over a dataset. In the first pass, individual items (sometimes called singletons) are counted, and those with high enough counts (or <em>supports</em>) are deemed to be <em>frequent singletons. </em>In the second pass over the data, only <em>candidate pairs</em> are counted. These pairs consist of two frequent singletons.</p><p>Most likely, the number of candidate pairs is considerably smaller than the number of possible pairs in the dataset. Even so, the number of candidate pairs can be quite high. This makes the second pass of the Apriori Algorithm very memory-intensive. In fact, it is often the most memory-intensive pass of the algorithm [1]. In these cases, reducing the memory requirements of the second pass would reduce the overall memory requirements for the algorithm.</p><p>The number of candidate pairs is closely related to the number of pairs that can be made using all of the frequent items. This is because any pair that consists of two frequent items is considered a candidate pair. That said, keep in mind that not all of these pairs will occur in the dataset. For example, even though {apple} and {banana} are both frequent items, it’s possible that the pair {apple, banana} will not appear in the dataset. Let’s call these pairs <em>possible candidate pairs</em> and reserve the term <em>candidate pairs</em> for the pairs that we actually count.</p><p>As a result, if we have <em>N</em> frequent items, the binomial coefficient <em>N choose 2</em> gives us the number of possible candidate pairs. The plot below illustrates the number of possible candidate pairs as a function of the number of frequent items. We can see that the memory requirements will grow quite quickly as the number of frequent items increases, since the number of possible candidate pairs skyrockets.</p><p>Again, keep in mind that some of these pairs may not necessarily show up in our dataset, but the number of pairs we’ll count (i.e. candidate pairs) is directly proportional to the number of <em>possible</em> candidate pairs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*253AwjA8b2hmCCn-lgbMfA.png" /><figcaption>Possible Candidate Pairs vs. Frequent Items</figcaption></figure><p>Here’s a similar graph, but with a logarithmic scale on the y-axis:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kv9FrLXtG5whTHed176ngQ.png" /><figcaption>Note the logarithmic scale on the y-axis</figcaption></figure><p>Relative to this, counting the number of frequent items doesn’t take a lot of memory, which means that there will be a lot of unused memory during the first pass of the Apriori Algorithm. Maybe it can be put to good use…</p><p>That’s exactly what Park, Chen, and Yu did in their Hash Based Algorithm for Mining Association Rules — named PCY for short, after the authors [1]. The algorithm uses hashing during the first pass to reduce the number of candidate pairs that are considered in the second pass.</p><h4>A Key Intuition</h4><p>Imagine that instead of getting the counts of each item in the dataset, we counted the number of items that started with each letter of the alphabet.</p><p>If the number of items that started with the letter <em>‘a’ </em>was less than our support threshold, we would know that none of the items that start with the letter <em>‘a’</em> are frequent. For example, if <em>apples</em> had been frequent, then the count of items starting with <em>‘a’</em> would have been above our threshold.</p><p>This is the key insight at the heart of the PCY Algorithm. Instead of applying it to single items, we apply it to pairs — since pairs cause our memory bottleneck. But the principle is the same.</p><p>(<strong>Note:</strong> In practice we use a modified hash table, not the first letters of items — but hopefully the example helps build an intuition for the algorithm)</p><h4>PCY with a Silly Hash Function</h4><p>To understand how the PCY Algorithm works, we’ll run through it with a simplistic (and silly) hash function. Keep in mind that the PCY Algorithm is a slightly modified version of the Apriori Algorithm.</p><p>As we encounter each basket during the first pass, we keep track of the occurrences of each singleton. We also build pairs from the items in the basket, hash the pairs, and keep track of the number of times each hash value has appeared.</p><p>The mechanism we’ll use to keep track of these counts is a modified hash-table. Each bucket in the hash-table corresponds to one of the hashes and contains a single integer that represents the number of times something has hashed to that bucket.</p><p>Note that this is very different from keeping track of all of the pairs that have hashed to that bucket.</p><p>For this example, we’ll hash these pairs using a simplistic hash function.</p><h4>Defining Our Hash Function</h4><p>For each pair, we take note of the first letter in each item’s name and put them together in a sorted string. Then we keep a hash-table with the counts of all the occurrences of these sorted strings.</p><p>To illustrate this, consider the baskets below.</p><blockquote>Let s = 3 be the support cutoff for being considered ‘frequent’.</blockquote><blockquote>Our dataset is:<br>Apples, Avocados, Bacon, Blueberries, Carrots<br>Almonds, Avocados, Bacon, Bananas, Durian<br>Almonds, Bacon<br>Avocado, Bananas<br>Almonds</blockquote><p>We read in the first basket and update our counts for items. This is the first basket we’re seeing, so each of the items will have a count of 1 once we process this basket.</p><p>Next, we generate all of the possible pairs from the items in this basket:</p><blockquote>The basket is:<br>Apples, Avocados, Bacon, Blueberries, Carrots</blockquote><blockquote>The possible pairs are:<br>{apples, avocados}<br>{apples, bacon}<br>{apples, blueberries}<br>{apples, carrots}<br>{avocados, bacon}<br>{avocados, blueberries}</blockquote><blockquote>and so on…</blockquote><p>For each of these pairs, we take the first letter in each item and put them together into a string, which we sort alphabetically. This is our hash function, which is a bit silly but hopefully will help build intuition.</p><p>Here are some pairs and their corresponding hashes:</p><blockquote>{apples, avocados} → ‘aa’<br>{apples, bacon} → ‘ab’<br>{apples, blueberries} → ‘ab’<br>…<br>{avocados, bacon} → ‘ab’</blockquote><blockquote>and so on…</blockquote><p>Next, we keep track of how many times each hash has appeared. For example, after the first basket, the hash <em>‘aa’</em> will have a count of 1, and the hash <em>‘ab’</em> will have a count of 4.</p><p>For example, the pair {<em>apples</em>, <em>bacon</em>} hashes to <em>‘ab’</em>, so when we encounter it, we’ll go to the bucket in the hash-table that corresponds to <em>‘ab’</em> and increase the count there from 0 to 1. The pair {<em>apples</em>, <em>blueberries</em>} also hashes to <em>‘ab’</em>, so it’ll cause us to increase the count in that bucket from 1 to 2.</p><p>Note that each of these pairs has only appeared once so far, but the count in this bucket is 2, since both pairs hash to the same bucket.</p><blockquote>Note that each of these pairs has only appeared once so far, but the count in this bucket is 2, since both pairs hash to the same bucket.</blockquote><p>We repeat this for all of the baskets in the dataset, and at the end of the entire first pass through the dataset, we get the results shown below. (Remember, our support threshold for an itemset to be frequent is s=3).</p><blockquote>Frequent Items:<br>Almonds, Avocados, Bacon</blockquote><blockquote>Counts of Pair Hashes:<br>‘aa’: 2<br>‘ab’: 10<br>‘ac’: 2<br>‘ad’: 2<br>‘bc’: 2<br>‘bd’: 2</blockquote><h4>What can we do with these hash counts?</h4><p>You might notice that the hash <em>‘ab’</em> has a count above our support threshold. If we’re only looking at these bucket-counts, though, it’s hard for us to determine how we got to that count.</p><p>On the one hand, it could be that a single pair with the hash <em>‘ab’ </em>appeared 10 times in the dataset. On the other hand, though, it could be that lots of different pairs all hashed to that bucket. Thus, the bucket could have a high count even if none of the pairs that hash to that bucket are frequent.</p><p>In contrast to this, the buckets with counts <strong>less</strong> than our support threshold are very important. Consider the bucket <em>‘ad’</em>, for example, which has a count of 2. We don’t know whether a single pair that hashes to <em>‘ad’</em> appeared twice in the dataset or two different pairs that hash to this bucket each appeared once. But if any of the pairs that hash to this bucket were frequent, the bucket would have a count of 3 or more. That means that <strong>any pair that hashes to the bucket <em>‘ad’</em> must be an infrequent pair, since that bucket’s count is below our support threshold of 3.</strong></p><blockquote>…any pair that hashes to the bucket ‘ad’ must be an infrequent pair, since that bucket’s count is below our support threshold of 3.</blockquote><p>For example, if the pair {<em>apple</em>,<em> durian</em>} had appeared 5 times in the dataset, then the bucket <em>‘ad’</em> would have a count of at least 5, since this pair hashes to the bucket <em>‘ad’</em>. In other words, the bucket count represents the maximum possible number of times that any pair that hashes to that bucket can appear in the dataset.</p><p>This allows us to narrow our definition of a candidate pair during the second pass through the dataset, which significantly lowers the number of possible candidate pairs. In particular, we’ll require that a pair hashes to a frequent bucket in order to be a candidate pair, in addition to being made up of frequent items.</p><h4>What Happens to the Hash-Table After the First Pass?</h4><p>During the second pass, we only need to know whether a bucket in the hash-table is frequent — we don’t really care about the particular count. Since <em>frequent vs. not frequent</em> is binary, we can replace the count in the hash-table with a single 1 or 0. That way, we reduce the memory footprint of each bucket in the hash-table from a 4-byte int, which stored the count, to a 1 bit flag, which tells us whether that bucket is frequent. The resulting hash-table is often called a <em>bitmap</em>.</p><h4>Hold on a second…</h4><p>If you’re watching closely, you may have noticed that in the small dataset provided here, keeping track of these hash counts doesn’t actually help us in any way. The pairs that we would have filtered out using the infrequent buckets are already filtered out by the fact that the items they contain are not frequent. This is because our dataset is artificially small.</p><p>With large datasets — and a large number of items sold in the store — this is extremely unlikely to occur. In practice, the deciding factor on whether PCY provides an improvement over Apriori is the percentage of possible candidate pairs that are eliminated by the hashing technique. We’ll take a closer look at this in a moment.</p><h4>A Quick Note on Our Hash Function</h4><p>One important thing to keep in mind here is that the hash function we’ve chosen is very contrived. The biggest flaw with this hash function is that hashes don’t have equal probabilities of occurring. (For a refresher on hash functions, read <a href="https://medium.com/weekly-data-science/hash-functions-for-data-mining-55e9c7760703">Hash Functions for Data Mining</a>, which describes some examples of hash functions we might use in production towards the end of the post.)</p><h4>Trade-offs with Hash-Table Size</h4><p>The main tradeoff faced when picking the size of the hash-table is between the memory footprint of the hash-table and the number of collisions that will be experienced.</p><p>Consider the case, for example, where the number of buckets in the hash-table is equal to the number of possible candidate pairs. In this case, the memory footprint of the hash-table is extremely large, and we may as well have just counted all of the candidate pairs.</p><p>On the other hand, if we make our hash-table extremely small — for example, a single bucket — we’ll experience a huge number of collisions, which is also not particularly useful.</p><p>The original paper explores hash-table sizes in more detail, and I encourage you to read it if you’re curious [1]. The online class <a href="http://mmds.org/">Mining Massive Datasets</a>, which has a corresponding textbook that is freely available through their website, also discusses the PCY algorithm in detail. The book claims that the break-even point for using the technique described in the PCY algorithm is when 2/3 of the possible candidate pairs are eliminated through the hashing process. I explore the math behind this claim in another post: <a href="https://medium.com/weekly-data-science/pcy-vs-apriori-909abb3fe4fb">Memory Usage of PCY vs. Apriori Algorithms</a></p><h4>Friends of the PCY Algorithm: Multistage and Multihash</h4><p>As the title of this post implies, there are several refinements that can be made to enhance the PCY algorithm — the two that we’ll explore here are the Multistage Algorithm and the Multihash Algorithm.</p><p>Both algorithms focus on applying the hash-based filtering from the PCY algorithm more than once in order to further reduce the number of possible candidate pairs.</p><h4>The Multistage Algorithm</h4><p>In the Multistage Algorithm, we start by conducting the first pass over the data just as we did in the PCY Algorithm. However, before moving onto counting candidate pairs, we conduct a <em>second</em> pass over the data and hash pairs into a second hash-table if and only if the following conditions are met:</p><ul><li>The pair is made up of frequent items</li><li>The pair hashes to a frequent bucket in our first bitmap</li></ul><p><strong>But be careful:</strong> If we use the same hash function that we used to create the first hash-table, we won’t be gaining any new information. <strong>The second hash-table needs to use a hash function that is independent of the first hash-table’s. </strong>If we don’t introduce a new hash function, we’ll end up with the exact same hash-table as before, except that the infrequent buckets will have been removed.</p><blockquote>If we don’t introduce a new hash function, we’ll end up with the exact same hash-table as before, except that the infrequent buckets will have been removed.</blockquote><p>Once the second pass through the data is complete, we create a bitmap from the second hash-table. Together, the two bitmaps that we’ve created will filter out a greater number of pairs than the first bitmap alone.</p><p>During the third pass, we count pairs that are made up of frequent items and hash to frequent buckets in both bitmaps. The added bitmap effectively reduces our number of false positives.</p><p>Before counting candidate pairs, we could elect to make any number of passes over the data that we choose. The goal here would be to filter out more infrequent pairs and reduce the memory footprint of the algorithm.</p><p>However, keep in mind that the hash-tables and bitmaps also take up memory, and there will be a point at which it no longer makes sense to continue making passes over the data. Plus, we have to consider that each pass over the data takes time.</p><blockquote>…keep in mind that the hash-tables and bitmaps also take up memory, and there will be a point at which it no longer makes sense to continue making passes over the data.</blockquote><h4>Can we hash things exclusively through the second (or nth) bitmap?</h4><p>No, we can’t. The reason is that the second bitmap was constructed from only a subset of all possible pairs. Consider, for example, a pair that is made up of frequent items but does not hash to a frequent bucket in the first bitmap. Since it doesn’t hash to a frequent bucket in the first bitmap, we know it’s not a frequent pair. But consider what might happen if we put this pair through the second bitmap. The second bitmap is totally uncharted territory for it, since it played no role in the construction of this bitmap. We might put it through and find that — just by chance — it hashes to a frequent bucket. If we only hashed this pair through the second bitmap, we might accidentally think that it’s a candidate pair. Using both bitmaps ensures that we’ll filter it out.</p><p>If we keep track of the order in which the bitmaps were created, we can save ourselves a bit of time by hashing pairs through the 1st bitmap before deciding whether to hash it through the second bitmap. That way, if it’s filtered out as infrequent, we don’t waste time on subsequent bitmaps.</p><blockquote>Remember: Bitmaps only provide information about the pairs that were used to construct them.</blockquote><h4>The Multihash Algorithm</h4><p>Like the Multistage Algorithm, the Multihash Algorithm also uses multiple hash-tables to filter out infrequent pairs. However, rather than making additional passes over the data, this algorithm simply creates more than one hash-table during the first pass. These hash-tables turn into bitmaps, which are used to filter out infrequent pairs during the second pass.</p><p>The number of hash-tables that we use can be tuned depending on the context. Using more hash-tables will — up to a point — mean that we’ll filter out more infrequent pairs.</p><p>Adding hash-tables requires making a choice — we can either increase the amount of memory that we’re using, or we can decide not to increase our memory usage and simply divide up the memory among the hash-tables.</p><p>Keep in mind that splitting memory among many hash-tables means that the hash-tables get smaller, resulting in more collisions. If we have too many collisions, we won’t be able to effectively filter out infrequent pairs.</p><p>When looking at trade-offs, considering the extreme cases usually helps build intuition. For example, consider the case where we have lots and lots of hash-tables, each of which has only one bucket. Each hash-table would then contain the total count of all pairs in the dataset — which provides no help.</p><blockquote>When looking at trade-offs, considering the extreme cases usually helps build intuition.</blockquote><h4>In Conclusion</h4><p>In Data Mining, which algorithms we use and how we tune their parameters is very context-dependent. In this post we’ve seen that using the PCY Algorithm will only reduce our memory footprint in certain situations. We’ve also seen that the number of passes / hash-tables used in the Multipass and Multistage algorithms are highly context-dependent.</p><h4>Implement, Implement, Implement!</h4><p>These context-driven decisions take practice. To gain a deeper understanding of them, I highly encourage you to take a shot at implementing these algorithms yourself.</p><p>If you’re looking for datasets with which to practice, I recommend:</p><ul><li><a href="https://github.com/weeklyDataScience/apriori">This Github repo</a> that I set up with example datasets</li><li>The <a href="https://www.kaggle.com/c/instacart-market-basket-analysis">Instacart Market-Basket Analysis competition on Kaggle</a></li></ul><p><em>Let me know what you thought of this post in the comments below.</em></p><p><em>And don’t forget to subscribe to Data Science Weekly to see more content like this.</em></p><h4>References</h4><p>[1]: <a href="https://www.researchgate.net/publication/2267911_An_Effective_Hash-Based_Algorithm_for_Mining_Association_Rules">Soo Park, Jong &amp; Chen, Ming-syan &amp; Yu, Philip. (1997). An Effective Hash-Based Algorithm for Mining Association Rules. Proceedings of the 1995 ACM SIGMOID international conference on Management of data ACM SIGMOID. 24. 10.1145/568271.223813.</a></p><p>[2]: <a href="http://mmds.org/">Mining Massive Datasets</a> — online class with free textbook</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecba67216190" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-data-science/the-pcy-algorithm-and-its-friends-ecba67216190">The PCY Algorithm and Its Friends</a> was originally published in <a href="https://medium.com/weekly-data-science">Weekly Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memory usage of PCY vs. Apriori Algorithms]]></title>
            <link>https://medium.com/weekly-data-science/pcy-vs-apriori-909abb3fe4fb?source=rss-e5aea0e80a38------2</link>
            <guid isPermaLink="false">https://medium.com/p/909abb3fe4fb</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Dan Isaza]]></dc:creator>
            <pubDate>Sat, 30 Jun 2018 02:54:25 GMT</pubDate>
            <atom:updated>2018-07-19T01:49:16.027Z</atom:updated>
            <content:encoded><![CDATA[<p>The free textbook <a href="http://mmds.org/">Mining Massive Datasets</a> makes the claim that at least 2/3rds of possible candidate pairs must be eliminated by the first pass of the PCY Algorithm in order for its memory footprint to be lower than that of the Apriori Algorithm. Here, I’ll go step-by-step through that claim to show you why that’s the case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bkJzceh1iCg1rJ6Dg8BUqQ.jpeg" /><figcaption><a href="https://unsplash.com/photos/1iVKwElWrPA">https://unsplash.com/photos/1iVKwElWrPA</a></figcaption></figure><p>First, let’s consider the memory usage of the Apriori Algorithm during the second step, which according to the <a href="https://www.researchgate.net/publication/2267911_An_Effective_Hash-Based_Algorithm_for_Mining_Association_Rules">original PCY paper</a> is typically the memory bottleneck for the algorithm.</p><h4>Memory Footprint of the Apriori Algorithm (2nd pass)</h4><p>The Apriori Algorithm uses a triangular matrix to keep track of how many times items co-occur in a basket. I’ve drawn out an example matrix and entered N/A in the spaces that we would not initialize.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hu5-fFNA1qd3OZ3jRoxLEQ.png" /><figcaption>Note that memory is not allocated for the bottom part of the matrix</figcaption></figure><p>Note that each row and column of the matrix corresponds to an item that is sold in the store. Let’s assume that we’re using a hashmap to keep track of which indices correspond to which items. All of our approaches will use this hashmap, so we’ll leave it out of our calculations.</p><h4>Finding the Memory Footprint of the Triangular Matrix</h4><p>The memory footprint of the triangular matrix will be:</p><blockquote>(Number of entries) x (Size of each entry)</blockquote><p>Each entry in the matrix is an integer. Since we’re dealing with a large dataset, we should assume that counts can get very large — so let’s use a 4-byte int to keep track of these counts.</p><p>The number of entries in the matrix is equal to the number of pairs that we can make out of all the frequent items. Note that <em>(n choose 2) </em>gives us that number, where <em>n</em> is the number of frequent items.</p><p>Thus, the total memory footprint of the triangular matrix is:</p><blockquote>(n choose 2) x 4 bytes</blockquote><p>Let’s compare this to the memory footprint of the PCY Algorithm.</p><h4>Memory Footprint of PCY Algorithm</h4><p>In the PCY Algorithm, infrequent pairs are eliminated using a hashing technique. It would be super convenient of all of these pairs happened to be at one end of the triangular matrix that we just described. However, that’s not the case. Before running the first pass of the algorithm, there’s no way for us to know which pairs will be eliminated as infrequent.</p><p>Moreover, if we drew out our triangular matrix and removed the infrequent pairs, we’d see what looks like a triangular slice of swiss cheese — the missing entries would be randomly spread out throughout the matrix.</p><blockquote>…if we drew out our triangular matrix and removed the infrequent pairs, we’d see what looks like a triangular slice of Swiss cheese…</blockquote><p>Unfortunately, there’s no way to avoid allocating memory for these infrequent pairs in the triangular matrix. Obviously, creating a full triangular matrix doesn’t provide a smaller memory footprint than the Apriori Algorithm, so we have to use a different approach.</p><p>We can keep track of the counts of pairs using tuples that look like this:</p><blockquote>(item, item, count)</blockquote><p>where each <em>item</em> is a 4-byte int, which corresponds to one of the items sold in the store — as tracked in our previously mentioned hashmap. Here, the couts are 4-byte ints, just as they were in the triangular matrix. Thus, each of the pairs we count will take up a total of 12 bytes of memory.</p><p>So the total memory usage for counting pairs in the PCY Algorithm will be:</p><blockquote>(Number of pairs counted) x (12 bytes)</blockquote><p>Remember, we’re only going to be counting pairs that are comprised of frequent items and hash to frequent buckets. Let <em>m</em> represent the number of pairs we count in the second pass of PCY.</p><h4>So, what’s the break-even point?</h4><p>Let’s set up their memory usages as an equation and solve it to get the break-even point.</p><p><strong>Remember:</strong></p><ul><li><em>n </em>is the number of frequent items</li><li><em>m</em> is the number of pairs counted in the PCY algorithm</li></ul><p>Using the memory usages outlined above, we can set up the equation:</p><p>(n choose 2) x 4 bytes = m x 12 bytes</p><p>Dividing both sides by 12 bytes yields:</p><p>(n choose 2) x (1/3) = m</p><p>Thus, we can see that the break-even point for memory usage is reached when the number of pairs we count in the PCY Algorithm is equal to one third of the number of pairs counted in the Apriori Algorithm.</p><p>This is equivalent to saying that we need to eliminate at least 2/3 of the pairs counted in the second pass of Apriori, which is the claim made by the book, so we’ve verified the claim.</p><p>Nice! 🎉</p><h4>Want to Learn More?</h4><p>Check out some of these posts for more insights:</p><ul><li><a href="https://medium.com/weekly-data-science/the-intuition-behind-the-apriori-algorithm-4efe312ccc3c">The Intuition Behind the Apriori Algorithm</a></li><li><a href="https://medium.com/weekly-data-science/finding-meaningful-associations-in-retail-data-6ababd031171">Finding Meaningful Associations in Retail Data</a></li><li>The PCY Algorithm and Its Friends</li><li>Subscribe to <a href="https://medium.com/weekly-data-science">Weekly Data Science</a> to stay in the loop!</li></ul><h4>Other Resources</h4><p>I highly encourage you to read the <a href="https://www.researchgate.net/publication/2267911_An_Effective_Hash-Based_Algorithm_for_Mining_Association_Rules">original PCY paper</a>, as well as check out <a href="http://mmds.org/">Mining Massive Datasets</a>.</p><p><em>Let me know what you thought of this post by leaving a comment below!</em></p><p><em>And don’t forget to subscribe if you want to see more content like this.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=909abb3fe4fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-data-science/pcy-vs-apriori-909abb3fe4fb">Memory usage of PCY vs. Apriori Algorithms</a> was originally published in <a href="https://medium.com/weekly-data-science">Weekly Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding Meaningful Associations in Retail Data]]></title>
            <link>https://medium.com/weekly-data-science/finding-meaningful-associations-in-retail-data-6ababd031171?source=rss-e5aea0e80a38------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ababd031171</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[introduction]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[retail-technology]]></category>
            <dc:creator><![CDATA[Dan Isaza]]></dc:creator>
            <pubDate>Wed, 20 Jun 2018 23:23:30 GMT</pubDate>
            <atom:updated>2018-07-19T01:45:12.190Z</atom:updated>
            <content:encoded><![CDATA[<p>Although this post will focus on finding associations in retail data, these same techniques can be applied to other types of data, including text and genetic sequences.</p><p>This post builds off of a previous post, <a href="https://medium.com/weekly-data-science/the-intuition-behind-the-apriori-algorithm-4efe312ccc3c"><em>The Intuition Behind the Apriori Algorithm</em></a><em>. </em>There, I discussed how to efficiently find frequent itemsets in shopping data. Here, I’ll focus on what to do once you’ve identified those frequent itemsets. It’s safe to assume that we’re dealing with the same data. (Example data is available on <a href="https://github.com/weeklyDataScience/apriori">this Github repository</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kMplDPmmCJkyaLD1YNa95A.jpeg" /><figcaption><a href="https://unsplash.com/photos/08bOYnH_r_E">https://unsplash.com/photos/08bOYnH_r_E</a></figcaption></figure><h4>Vocabulary Recap</h4><p>If you’ve read the <a href="https://medium.com/weekly-data-science/the-intuition-behind-the-apriori-algorithm-4efe312ccc3c">Apriori post</a>, these terms will be familiar.</p><ul><li>Our dataset consists of shopping carts at time of checkout. We call these <em>baskets.</em></li><li>Baskets consist of items. Groups of items are called <em>itemsets</em>.</li><li>The number of baskets that an itemset appears in is called the <em>support</em> of that itemset.</li><li>We deem an itemset to be a <em>frequent itemset</em> if its support is above some threshold that we choose.</li><li><strong>Remember: </strong>If an itemset is frequent, all subsets of that itemset are also frequent. (This concept is discussed in detail in the Apriori post.)</li></ul><h4>What is an association rule?</h4><p>An <em>association rule</em> implies that a particular item is likely to occur given the presence of some itemset.</p><blockquote>An <em>association rule</em> implies that a particular item is likely to occur given the presence of some itemset.</blockquote><p>Let <em>I</em> be the itemset {eggs, flour}. Let <em>j</em> be the item {milk}. Then <em>I → j </em>is an association rule that implies that {milk} is likely to occur in a shopping cart if {eggs, flour} occurs.</p><p>On its own, this association rule doesn’t tell us anything. We want to measure how significant or important our rule is. After all, maybe the appearance of milk is not affected by the presence of eggs and flour. Or maybe shoppers are <em>less likely</em> to buy milk when they buy eggs and flour.</p><p>We need some way of capturing this information.</p><h4>Confidence</h4><p>The <em>confidence</em> of an association rule is an important building block. It represents the ratio between the number of times that <em>I </em>and<em> j </em>have appeared together and the number of times that <em>I </em>has appeared on its own.</p><p>Confidence essentially answers the question: <em>Out of all the times that people bought eggs and flour, how many times did they also buy milk? </em>Or, more precisely: <em>What proportion of the time?</em></p><blockquote>Confidence essentially answers the question: <em>Out of all the times that people bought eggs and flour, how many times did they also buy milk?</em></blockquote><p>Mathematically, we can say:</p><blockquote>Confidence(I →j) = Support(I ∪ j) / Support(I)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ae0hWBCl_ypMWtxXzQt37A.png" /><figcaption>Definition of confidence</figcaption></figure><p>In our example, <em>I </em>∪ <em>j</em> is the set {eggs, flour, milk}.</p><p>Note that every time the set {eggs, flour, milk} occurs, the set {eggs, flour} also occurs. This means that Support(I) ≥ Support(I ∪ j) ≥ 0, since supports must be greater than or equal to zero.</p><p>Thus, we know that 1 ≥ Confidence(I → j) ≥ 0.</p><h4>Practice with Confidence</h4><p>Let’s work through an example together.</p><p>What is the confidence of the association rule {eggs, flour} → {milk} in the dataset below?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qLV0VqhybUTC3_whMgAuog.png" /></figure><p>First, notice that:</p><blockquote>Support({eggs, flour}) = 3</blockquote><blockquote>and</blockquote><blockquote>Support({eggs, flour, milk}) = 3</blockquote><p>Next, calculate the confidence:</p><blockquote>Confidence({eggs, flour} → {milk}) = Support({eggs, flour, milk}) / Support({eggs, flour})</blockquote><blockquote>Confidence({eggs, flour} → {milk}) = 3 / 3 = 1</blockquote><p>Nice! Our rule has the highest possible confidence value. That must be good, right? …Actually, not quite.</p><p>What if {milk} occurs frequently independently of whether {eggs, flour} is present? Then we might observe a large confidence value despite the fact that <em>I </em>and<em> j </em>are independent.</p><p><strong>What if people always buy milk?</strong></p><p>Consider the case where every shopping cart contains milk.</p><p>Remember, confidence answers the question: <em>What proportion of the time that I appears does j also appear?</em></p><p>If people always buy milk, the answer will be 1. We can clearly see that in this case, buying eggs and flour does not influence people’s decision to purchase milk, so this confidence score is not particularly helpful.</p><h4>Interest</h4><p>The notion of <em>interest</em> can help us here. It extends the idea of confidence by subtracting out the proportion of baskets in which <em>j</em> appears.</p><blockquote>Interest(I → j) = Confidence(I → j) - Pr(j),</blockquote><blockquote>where Pr(j) = Support(j) / (Num. Baskets)</blockquote><p>By doing this, we account for the fact that <em>j</em> may occur independently of <em>I</em>.</p><p>Since confidence is a number in the range [0, 1] and the proportion of baskets in which <em>j</em> occurs is also a number in the range [0, 1], the interest of an association rule is in the range [-1, 1].</p><p>When an association rule has an interest close to 0, it indicates that the presence of <em>I</em> does not imply much about the presence of <em>j</em>. When a rule’s interest has an absolute value that is relatively large (typically above 0.5 or so), it indicates that this is a meaningful association in the dataset. Negative interest indicates that the presence of <em>I</em> discourages the presence of <em>j</em>, and positive interest indicates that the presence of <em>I</em> encourages the presence of <em>j</em>.</p><h4>Practice with Interest</h4><p>What is the interest of the association rule {eggs, flour} → {milk} in the dataset below? (same dataset as before)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qLV0VqhybUTC3_whMgAuog.png" /></figure><p>We know from before that the confidence of this rule is 1. We can see that {milk} shows up in 3 out of the 4 baskets, so Pr(j) = 3/4, or 0.75.</p><p>Thus, Interest({eggs, flour} → {milk}) = 1 – 0.75 = 0.25.</p><p>Note that if milk had appeared in every basket, the rule would have an interest of 0.</p><p>Thus, we can see that although our rule had high confidence, it’s not actually a meaningful association in the dataset, as indicated by its low interest.</p><h4>A closer look at one of the example datasets</h4><p>If we look at the <a href="https://github.com/weeklyDataScience/apriori/blob/master/dataset_100000_baskets_5000_objects.txt">example dataset with 100,000 baskets and 5,000 possible items</a>, we’ll see that almost all of the association rules have an interest of zero. This is to be expected, since I generated the dataset using <a href="https://github.com/weeklyDataScience/apriori/blob/master/dataset_builder.py">this script</a>, in which items are added to baskets independently of each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R9YkhCFRefCbF-Rqo0JOJA.png" /><figcaption>As expected, these are a bunch of meaningless associations.</figcaption></figure><p>Despite the fact that items are independent of each other, we can see that there are some association rules with non-zero interest scores. This happens purely by chance and does not imply that the rules are meaningful. That’s why we need to ensure that rules have relatively high interest scores before deeming them meaningful associations.</p><h4>Want to practice your skills?</h4><p>Try finding meaningful associations in the example datasets I’ve set up <a href="https://github.com/weeklyDataScience/apriori">on Github</a>, or check out <a href="https://www.kaggle.com/c/instacart-market-basket-analysis">Instacart’s Market-Basket Analysis Challenge</a> on Kaggle.</p><h4>Coming Soon</h4><p>I’ll be writing a quick post detailing why the expected interest of <em>I → j </em>is 0 when <em>I</em> and <em>j</em> are independent. Keep an eye out!</p><p><em>Thanks for reading!</em></p><p><em>Let me know what you think of this post in the comments below — and if there are any topics you’d like to see me write about, please let me know!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ababd031171" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-data-science/finding-meaningful-associations-in-retail-data-6ababd031171">Finding Meaningful Associations in Retail Data</a> was originally published in <a href="https://medium.com/weekly-data-science">Weekly Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hash Functions for Data Mining]]></title>
            <link>https://medium.com/weekly-data-science/hash-functions-for-data-mining-55e9c7760703?source=rss-e5aea0e80a38------2</link>
            <guid isPermaLink="false">https://medium.com/p/55e9c7760703</guid>
            <category><![CDATA[data-mining]]></category>
            <category><![CDATA[hashing]]></category>
            <category><![CDATA[introduction]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Dan Isaza]]></dc:creator>
            <pubDate>Wed, 20 Jun 2018 19:27:16 GMT</pubDate>
            <atom:updated>2018-07-19T00:23:48.624Z</atom:updated>
            <content:encoded><![CDATA[<p>If you work in a technical field, chances are you’ve heard of hash functions. They’re used extensively in cryptography and data structures — you might have encountered them in public-key cryptography or when learning about hash tables. Non-technical folks have likely heard of them in the context of Bitcoin mining.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t1vQAO8hJtdLSZHz1-4cGg.jpeg" /><figcaption><a href="https://unsplash.com/photos/PO8Woh4YBD8">https://unsplash.com/photos/PO8Woh4YBD8</a></figcaption></figure><p>Hash functions — it turns out — are incredibly useful for many things, including data mining and machine learning. This post is intended to be a quick introduction to the kinds of hash functions that are commonly used for data mining. Many algorithms for analyzing shopping trends, text documents, and even genetic information rely on the concepts discussed below.</p><blockquote>Many algorithms for analyzing shopping trends, text documents, and even genetic information rely on the concepts discussed below.</blockquote><h4>What is a hash function?</h4><p>A hash function is a deterministic function that maps inputs of arbitrary sizes to outputs of a fixed size. That means that there are an infinite number of possible inputs but only a finite number of possible outputs. We call these outputs <em>hashes, hash values</em>, or <em>digests</em>.</p><p>For example, imagine a function that takes in non-empty strings that contain the ASCII characters a-z and maps them to their first character. There’s a glaring issue with this hash function that we’ll discuss later, but for now let’s use it as our example. (See if you can identify the issue)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9dA4dVperoUNnynHQtrJ2A.png" /><figcaption>A pretty contrived example…</figcaption></figure><p>We can see that there are many possible inputs — an infinite number, in fact — and only 26 possible outputs.</p><p>Let’s use this example to explore some of the common properties of the hash functions we’ll encounter in data mining applications.</p><h4>Common Properties of Hash Functions in Data Mining</h4><ul><li><strong>They have a fixed and finite number of possible outputs which is smaller than the number of possible inputs. </strong>This has several implications. First, it means that multiple inputs can hash to the same output (the way “abc” and “apple” both has to the letter “a” in our example). We call that a <em>collision. </em>Second, it means that if you were to hash all of your data and store the counts of the hashes, you would likely be storing much less information than if you stored the counts of items in the dataset (depending on your data and which hash function you choose). For example, keeping a count of how many times each word in a book occurs would take much more memory than keeping track of how many words in the book start with each letter in the alphabet.</li></ul><blockquote>…multiple inputs can hash to the same output. We call that a collision<em>.</em></blockquote><ul><li><strong>Most hash functions cannot be reversed. </strong>Given a particular output, it’s not possible to determine what the original input was that generated that output. In our example, if we were told that some input hashed to the output “a”, it would be impossible for us to say whether that input had been “apple”, “aardvark”, “abc”, or some other string starting with “a”.</li><li><strong>Hash functions are deterministic. </strong>A particular input will <em>always generate the same output</em>. This rule is true for hash functions regardless of the discipline in which they’re being used.</li><li><strong>Outputs should all have an equal probability of occurring. </strong>This is important because it affects the way in which collisions occur. We typically want all inputs to have equal probabilities of collisions. As you may have guessed, this is where there’s a glaring gap in our example function. The probability of an output occurring is equal to the probability of a string starting with that particular letter. Since we don’t know anything about the distribution of input strings, it’s not safe to assume that our outputs will all have equal probabilities of occurring. If, for example, we’re choosing strings from an English dictionary, there will be more words that start with ‘t’ than words that start with ‘x’, for instance.</li></ul><blockquote>We typically want all inputs to have equal probabilities of collisions.</blockquote><h4>Common hash functions and an alternative to our example</h4><p>One very common hash function is <a href="https://en.wikipedia.org/wiki/MD5">Message Digest 5</a>, or MD5 for short. The <a href="https://en.wikipedia.org/wiki/Secure_Hash_Algorithms">Secure Hash Algorithms</a> (SHA) is a family of hash functions that are quite common. <strong>But be very careful:</strong> Many hash functions, including MD5 and several of the SHA functions have been found to be unsafe for cryptographic use. For data mining, however, this doesn’t concern us.</p><p>To fix the non-uniformity problem we observed with our example, we could simply use the MD5 function and keep the first N digits of the MD5 hash. Looking at <a href="https://en.wikipedia.org/wiki/MD5#Pseudocode">pseudocode for the MD5 algorithm</a> shows us that characters have an equal probability of occurring in the hash, which satisfies our uniformity condition. To tune the number of expected collisions, we can simply choose a different value of N.</p><h4>What’s the expected number of collisions?</h4><p>Test your knowledge of hash functions by trying to solve the problem below.</p><p>Let’s assume:</p><ul><li>We pick 20,000 unique words</li><li>We hash them according to the method described above, using the MD5 hash and keeping the first N characters of the resulting hash string. These first N characters become the final hash string that we’ll use.</li><li>What is the expected number of collisions for the hash string that consists of all zeroes when N=1? N=2? N=5?</li><li>Why might we want to avoid picking N=5?</li></ul><p><strong>Note: </strong>MD5 hashes are alphanumeric strings.</p><h4>What can I do with Hash Functions?</h4><p>There are some really cool applications that I’ll be writing about in the future, including Bloom Filters, Locality Sensitive Hashing, and the PCY Algorithm — an improvement to the Apriori Algorithm, which I wrote about in <a href="https://medium.com/weekly-data-science/the-intuition-behind-the-apriori-algorithm-4efe312ccc3c"><em>The Intuition Behind the Apriori Algorithm</em></a><em>. </em>Keep an eye out for these posts in the future.</p><p><em>Are you excited about data science / machine learning / data mining? Is there anything in particular you’d like to see me write about? Let me know in the comments below!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55e9c7760703" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-data-science/hash-functions-for-data-mining-55e9c7760703">Hash Functions for Data Mining</a> was originally published in <a href="https://medium.com/weekly-data-science">Weekly Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Intuition Behind the Apriori Algorithm]]></title>
            <link>https://medium.com/weekly-data-science/the-intuition-behind-the-apriori-algorithm-4efe312ccc3c?source=rss-e5aea0e80a38------2</link>
            <guid isPermaLink="false">https://medium.com/p/4efe312ccc3c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Dan Isaza]]></dc:creator>
            <pubDate>Fri, 15 Jun 2018 05:59:38 GMT</pubDate>
            <atom:updated>2018-07-19T06:25:06.194Z</atom:updated>
            <content:encoded><![CDATA[<p>Analyzing shopping trends is a pretty big deal in data science, and market-basket analysis is one way in which that’s done. Techniques in this sub-field seek to understand how buying certain items influences the purchase of other items. This allows retailers to increase revenue by up-selling or cross-selling their existing customers.</p><p>Understanding the Apriori Algorithm is foundational to building your understanding of many techniques for market-basket analysis. It’s used to find groups of items that occur together frequently in a shopping dataset. This is usually the first step to finding new ways in which to promote merchandise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ar6BogyV_UXzSU5cRqt7Eg.jpeg" /><figcaption><a href="https://unsplash.com/photos/L6g30JaQ5Tc">https://unsplash.com/photos/L6g30JaQ5Tc</a></figcaption></figure><h3>So… What does shopping data look like?</h3><p>Imagine we have a file where each line represents a customer’s shopping cart at checkout time. Let’s call this a <em>basket</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9QhBctFPyo7_RDGHw61Smw.png" /><figcaption>Each line above represents a basket</figcaption></figure><p>Each basket is made up of items. Our objective is to find sets of items that occur frequently together in the dataset. We’ll call these <em>frequent itemsets</em>.</p><blockquote>Our objective is to find sets of items that occur frequently together in the dataset.</blockquote><p>We’ll set our own definition of what <em>frequent</em> means. This definition will likely change based on the number of baskets in the dataset. Typically, we’ll be interested in frequent itemsets of a particular size. Today, let’s assume that we’re looking for frequent triples (i.e. itemsets of size 3).</p><p>As we continue exploring below, let’s use <a href="https://github.com/weeklyDataScience/apriori/blob/master/dataset_100000_baskets_5000_objects.txt">this example dataset</a> to enhance the discussion. It takes on the format described above.</p><h4>Some quick stats about the example dataset:</h4><ul><li>It contains 100,000 baskets</li><li>There are 5,000 items that are sold at this particular supermarket</li><li>Each item is a fake ISBN number (you know, like for books 📚)</li></ul><p>Let’s also say that appearing more than 1,000 times makes an itemset <em>frequent</em>. (<strong>Note:</strong> The count of an itemset is often called its <em>support.</em>)</p><h3>The Naïve Approach</h3><p>The first thing that comes to mind is to scan through the dataset, count up the occurrences of all the triples, then filter out the ones that aren’t frequent.</p><p>The naïve approach is appealing for its simplicity. However, we end up counting a lot of triples.</p><p>In the example dataset, there are over 7 million total triples, but only 168 of them are frequent.</p><blockquote>There are over 7 million total triples, but only 168 of them are frequent.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IPSu5lfxXEyJlTXG3oIXcQ.png" /><figcaption>Lots of triples, but not a lot of frequent triples.</figcaption></figure><p><strong>This is a problem for two reasons:</strong></p><ul><li>Keeping track of the counts for those millions of triples takes up a lot of space.</li><li>Building and counting all of those triples takes a lot of time.</li></ul><p>If only there were a way to avoid building and counting so many triples…</p><h3>A Key Intuition</h3><p>There <em>is</em> a way to avoid doing that! And it relies on a key piece of information. Don’t worry, we’ll break it down together, but here it is:</p><p>The key intuition is that a<em>ll subsets of frequent itemsets are also frequent itemsets</em>.</p><p>To add some clarity, consider these four baskets:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qLV0VqhybUTC3_whMgAuog.png" /><figcaption>Eggs, flour, and milk seem to be a pretty popular combo</figcaption></figure><p>We can clearly see that the set {eggs, flour, milk} occurs 3 times. And at risk of sounding overly simplistic: each time we see the group {eggs, flour, milk}, we are seeing the individual items {eggs}, {flour}, and {milk}. As a result, we can safely say that the support (i.e. count) of {eggs} will be at least as large as the support of the set {eggs, flour, milk}. The same applies to flour and milk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UdnC9BwDb7CBPNzpW4nsag.png" /><figcaption>Our newfound conclusions</figcaption></figure><p>In fact, we can extend this fact to pairs of items inside of the set {eggs, flour, milk}. That means Support({eggs, flour}) ≥ Support({eggs, flour, milk}). Again, that’s because the set {eggs, flour} necessarily occurs whenever the set {eggs, flour, milk} occurs, since it’s a subset of it. Of course, this generalizes to sets and subsets of larger sizes.</p><h3>Okay… So what?</h3><p>The fact outlined above becomes useful when you think about it in the other direction. Since sugar, for example, only occurs once, we know that any set that contains sugar can only occur once.</p><p>Think about it: if a triple that contained sugar occurred more than once, that would mean that sugar occurs more than once. And since sugar only occurs once, we can guarantee that any triple that contains sugar will not appear more than once.</p><p>That means that we can simply ignore all of the sets that contain sugar, since we know that they can’t be frequent itemsets.</p><p>We can apply this same logic to larger subsets as well. In the image above, {milk} and {butter} each appear three times. But as a pair, they only appear together twice (i.e. Support({milk, butter}) = 2). This means that any triple that contains the pair {milk, butter} can appear at most 2 times. When scanning for triples that appear 3 or more times, we could simply ignore {milk, butter, flour} since it contains {milk, butter}, so we know that it <em>must</em> appear no more than 2 times.</p><p>The Apriori Algorithm makes use of this fact to eliminate needlessly constructing and counting itemsets.</p><h3>The Apriori Algorithm</h3><p>Unlike the naïve approach, which makes a single pass over the dataset, the Apriori Algorithm makes several passes — increasing the size of itemsets that are being counted each time. It filters out irrelevant itemsets by using the knowledge gained in previous passes.</p><p>Here’s an outline of the algorithm:</p><h4>First Pass</h4><ul><li>Get the counts of all the items in the dataset</li><li>Filter out items that are not frequent</li></ul><h4>Second Pass</h4><ul><li>Get the counts of pairs of items in the dataset. BUT: only consider pairs where both items in the pair are frequent items. (These are called <em>candidate pairs.</em>)</li><li>Filter out pairs that are not frequent.</li></ul><h4>Third Pass</h4><ul><li>Get the counts of triples in the dataset. BUT: only consider <em>candidate triples. </em>If any of the items in the triple are not frequent, the triple is not a candidate triple. If any of the <em>pairs of items</em> in the triple are not frequent, the triple is not a candidate triple.</li><li>Filter out triples that are not frequent.</li></ul><h4>Nth Pass</h4><ul><li>Get the counts of candidate itemsets of size N. (<strong>Remember:</strong> If any of the subsets of items in the itemset are not frequent, then the itemset cannot be frequent.)</li><li>Filter out itemsets that are not frequent.</li></ul><p>While this algorithm ends up taking more passes over the data, it saves a lot of time by cutting down on the number of itemsets that it builds and counts.</p><p>Take a look at these stats from our example dataset:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ewdDCGQaI50cHMDOJuTWbA.png" /><figcaption>We only consider 352 of the 7m+ possible triples.</figcaption></figure><p>Ultimately, this reduction in the number of itemsets considered is what makes the Apriori Algorithm so much better than the naïve approach.</p><h3>Want to truly understand it…?</h3><p>I encourage you to implement the Apriori Algorithm yourself, as a way of cementing your understanding of it.</p><p>To get you started, I’ve set up a <a href="https://github.com/weeklyDataScience/apriori">Github repo</a> with some example datasets and other resources to get you started.</p><p>Here are two challenges — one much harder than the other.</p><h4>The Challenge</h4><p>Extract frequent triples from the example datasets by implementing the Apriori Algorithm and conducting three passes through the dataset.</p><p>Check you implementation by also implementing the naïve approach and comparing your results.</p><h4>The Bonus Challenge</h4><p>Implement the Apriori Algorithm such that it will extract frequent itemsets of any given size. For example, if I want to extract frequent itemsets of, say, size 13 it should be able to do that.</p><p>The Github repo includes a script that you can use to generate very large datasets. Use this to test your more general implementation.</p><p>(If you choose to take on the bonus challenge, I encourage you to do the 3 pass implementation first. I think it’ll help build your understanding.)</p><h4>Avoid this common mistake</h4><p>One of the most common mistakes when implementing this algorithm happens when checking for candidate itemsets. Folks often remember to check if the individual items in an itemset are frequent, but they forget to check if <em>all subsets</em> of the current itemset are frequent.</p><blockquote>Folks often remember to check if the individual items in an itemset are frequent, but they forget to check if all subsets of the current itemset are frequent.</blockquote><p><strong>Remember:</strong> Triples contain pairs. Quads contain triples and pairs. And so on.</p><h3>Let’s chat!</h3><p>If you take on either of the challenges above, please let me know. I’d love to swap implementations of the algorithm with you and hear about your experience.</p><p>I’ve listed my email on the <a href="https://github.com/weeklyDataScience/apriori">Github repo</a>, so please feel free to reach out.</p><p><em>Want to stay in the loop about this kind of stuff? </em><a href="http://eepurl.com/dxKiQ9"><em>Join my mailing list</em></a><em>, where I share Data Science resources each week.</em></p><p><em>Let me know your thoughts in the comments below!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4efe312ccc3c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-data-science/the-intuition-behind-the-apriori-algorithm-4efe312ccc3c">The Intuition Behind the Apriori Algorithm</a> was originally published in <a href="https://medium.com/weekly-data-science">Weekly Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Retail Analysis Challenge]]></title>
            <link>https://medium.com/weekly-data-science/retail-analysis-challenge-bcd2d1ca1e82?source=rss-e5aea0e80a38------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcd2d1ca1e82</guid>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[exploratory-data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Dan Isaza]]></dc:creator>
            <pubDate>Thu, 07 Jun 2018 21:23:27 GMT</pubDate>
            <atom:updated>2018-07-19T01:47:55.721Z</atom:updated>
            <content:encoded><![CDATA[<p>This post introduces a quick challenge intended to help data science candidates prepare for job interviews. It includes an associated <a href="https://github.com/WeeklyInterviewQuestion/Week-1">Github repository</a> with data for the challenge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*olqpOE64vPwHJkdcFwQ6_g.jpeg" /><figcaption><a href="https://unsplash.com/photos/ZKNsVqbRSPE">https://unsplash.com/photos/ZKNsVqbRSPE</a></figcaption></figure><p>Let’s imagine that a large retailer hires you as a freelance data scientist to analyze trends from their brick-and-mortar stores. They want to identify patterns in shopping behaviors that they can use to increase their revenues.</p><p>The client doesn’t know much about data science or statistics, so they’re trusting you to bring your know-how to the table. That is to say, they don’t have a specific approach in mind. They’re only interested in business outcomes.</p><p>When they present you with the data, you’re given a file with many <em>baskets. </em>Each basket represents the items in a user’s shopping cart at the time of checkout.</p><h4>The Challenge</h4><p>Analyze the data and report on your findings.</p><p><em>What methods did you use? What recommendations do you have for the client? What additional information would you like to see?</em></p><h4>Logistics</h4><p>I’ve made the challenge dataset <a href="https://github.com/WeeklyInterviewQuestion/Week-1">available on Github</a>.</p><p>You can send your findings to me via email at: <em>daniel (dot) isaza (dot) 93 (at) gmail</em></p><p>If you’re onto something cool, I may ask if I can give you a shoutout on the Weekly Data Science Interview mailing list. And be sure not to miss my walkthrough of my own analysis, which I’ll be sending out on 7/14 (<a href="https://manage.campaignzee.com/RA8sG3Sch0">join here for $1/week</a>).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcd2d1ca1e82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-data-science/retail-analysis-challenge-bcd2d1ca1e82">Retail Analysis Challenge</a> was originally published in <a href="https://medium.com/weekly-data-science">Weekly Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>