<?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 Sam Stack on Medium]]></title>
        <description><![CDATA[Stories by Sam Stack on Medium]]></description>
        <link>https://medium.com/@sam.stack?source=rss-9b5276a5f34d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FdvLITdIziKlr8bCakxSVw.jpeg</url>
            <title>Stories by Sam Stack on Medium</title>
            <link>https://medium.com/@sam.stack?source=rss-9b5276a5f34d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 17:19:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sam.stack/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[Situational Shading]]></title>
            <link>https://medium.com/@sam.stack/situational-shading-2b10d9197eb6?source=rss-9b5276a5f34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b10d9197eb6</guid>
            <category><![CDATA[design]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Sam Stack]]></dc:creator>
            <pubDate>Wed, 16 Jan 2019 19:52:23 GMT</pubDate>
            <atom:updated>2019-01-16T19:52:23.544Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XQmUi4fmwxo-aqeSI6OqyQ.png" /><figcaption>Seaborns cmap options : “Reds”, “Blues”, “Plasma”, “Rainbow”, ”gist_ncar”</figcaption></figure><p>In a recent project I was working on, I created a heatmap to show count densities of two overlapping categorical features. However, the resulting heatmap was not what I really wanted. I was very interested in cells that were white or very light to indicate very low to 0 counts, but because of the range and odd distribution of my data, this did not turn out as expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0EpdCa-RmVui9Vo6Wbtfg.png" /><figcaption>Heatmap with standard scale shading</figcaption></figure><p>Anything thats not on the top-left to bottom-right diagonal is hard to gain insight from because it is all just too light!</p><p>My Solution was to modify the gradient by which the colors were generated. <br><em>Coming back to this, I realize it was actually the long way around as I could have modified the data to get the desired results.</em></p><p>Most shading gradients are consistent in their progression, as you step through it, every step darker or lighter is the same as the previous. This was no good for my data and instead I believed a gradient that followed a logistic pattern would be more beneficial to look at my data through. This logistic gradient would have larger jumps in darkening early on and more subtle jumps later.</p><p>I created a function to apply this logarithmic approach to the blue values in and RGB combination to make them darken more quickly. The result is below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oYILL_uTSpD63dsaib26wA.png" /></figure><p>As you can see the log scale gets darker much quicker and later on the changes in colors become less and less noticeable. Below is the result of applying the Log Scaled Shading to the Seaborn heatmaps cmap option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Xm6LHp-0l08Aa247nSj7Q.png" /><figcaption>Heatmap with Logarithmic scale shading</figcaption></figure><p>This was much more useful for my intentions.</p><h4>I’m an idiot…</h4><p>I mentioned earlier that I’m an idiot and did this in the more complicated of the way possible. Instead of transforming the color map, I should have just transformed my data with a <em>df.apply(np.log1p)</em> to get the logged version of the data and then made the heatmap with that, which resulted in the below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VhvgvfwI4UtkC_wB5dDJ5A.png" /><figcaption>Heatmap made with taking the Log of the original values.</figcaption></figure><h4>Ethical Considerations</h4><p>Its an important note that in this post I am adjusting the way the data is perceived from how it truly exists. In this situation my intent is not to fool the audience or exaggerate signal, it is just a means for me to observe the elements of the data I am interested in to a better degree. I would not use or recommend using these tactics in a presentation environment without explicitly stating the transformation, the reasoning and what was meant to be observed as a result.</p><h4>Seaborn’s Color Map Options</h4><p>If you’re interesting in <em>sea</em>ing all of Seaborn’s color map options, I made a <a href="https://github.com/samuel-stack/Seaborn-Cmap-Options/blob/master/Seaborn-Cmap-Options.ipynb">repo showing all of them</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b10d9197eb6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s That Pokémon?]]></title>
            <link>https://medium.com/@sam.stack/whats-that-pok%C3%A9mon-8c838a02f3d8?source=rss-9b5276a5f34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c838a02f3d8</guid>
            <category><![CDATA[pokemon]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Sam Stack]]></dc:creator>
            <pubDate>Mon, 14 Jan 2019 19:57:13 GMT</pubDate>
            <atom:updated>2019-01-17T23:55:49.834Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Statistically determining what Pokémon types should be introduced in the future.</em></p><p>Like many kids that grew up in the 90s, I grew up with pokémon. I think the first video game I ever owned was Pokémon Red for the Game Boy Color. Unlike many kids from the 90s, pokémon continued to stick with me throughout my life, however I didn’t much progress beyond the third generation and even then it was my younger brother who had become the household Pokémon Master. For those of you that did not succumb to the pokémon craze, you probably at least know that they are little monsters children use to “battle” one another. Additionally, the number of different pokémon that exist changes, with 100 or so new pokémon being introduced every few years. These introductions of new pokémon are labeled “Generations”.</p><p>Within new generations we not only see new pokémon, but also new combinations of abilities and types. Today I’m going to focus on exploring Pokémon types with the intent on finding new types of pokémon to introduce as I believe starting with a typing in mind can help fuel the creative juices in order to develop an actual pokémon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*lbsCJaP0SKzGckYlw9Kosg.jpeg" /></figure><p>To the left are three pokémon of different types. In the top left we have Squirtle, who is a Water type pokémon. Water types can use moves that involve water like Water Gun or Hydropump which are very strong against fire type pokémon such as Charmander (top right). On the other hand, water type Pokémon have weaknesses such as electricity. The pokémon games, show, and manga all follow this complex system of type checks and balances, where specific types have strengths against some types and weaknesses against others.</p><p>The most important note that goes along with these typing is that a pokémon can have up to two types. Below on the left is Moltres, who is both fire and flying types, on the right is Omanyte, who is both water and rock types. Having two types means a pokémon is exposed to both the strengths and weaknesses of the both types.</p><p><em>If you understand pokémon, or just don’t care about the gritty details, I recommend skipping down to </em><strong><em>Distribution Analysis.</em></strong></p><h3>Recommendation Process</h3><p>It is my goal today to focus on type pairings and recommend them for future generations. I want to identify pairings that do not exist and calculate if they would be a balanced fit considering the distribution of others.</p><p>I want to identify pairings that are rare or do not exist and assess how they would fit in to the current structure. In order for me to recommend them, I’m going to look at some summary stats that exist for all current pokémon and identify ranges of these values that type pairings must fall into.</p><p>Before we can go about making recommendations about type combinations, let’s take a look at the results of combinations. What I’m trying to say is, we don’t want to recommend a type combination that is too powerful. That it can have an offensive or defensive advantage over all or most other types and be an offensive and/or defensive juggernaut.</p><p>First, a brief explanation how damage is calculated. In the video games, damage dealt relies on two things: the damage multiplier and the base damage of the attack. Base damage varies enormously, as it is a combination of the pokemon’s level and the specific moves damaging abilities. However, the damage multiplier is a consistent value and is more relevant to our analysis as it is directly affected by typing.</p><p><strong>Example:</strong></p><ul><li>A water attack being used against a fire pokémon with have a x 2 damage multiplier(water is strong against fire)</li><li>A fire attack being used against a water pokémon will have a x 0.5 damage multiplier(fire is weak against water).</li><li>A fighting attack being used against a ghost pokémon will have a x 0 damage multiplier and do no damage (you can’t punch a ghost).</li></ul><p><strong>Attacking a Pokemon who only has one type (like Fire or Water)</strong></p><ul><li>Damage Multiplier * Base Damage</li></ul><p><strong>Attacking a Pokemon with 2 different Types(Fire/Flying or Ice/Ground)</strong></p><ul><li>(Damage Multiplier(type 1) * Damage Multiplier(type 2) * Base Damage</li></ul><p>Given this set up, in order to keep things balanced…</p><ul><li>1. We do not want to propose a combination that has a offensive type advantage over all or most other types.</li><li>2. We do not want to propose a combination that has a defensive advantage over all or most other types AND has defensive immunity over many types.</li></ul><p>Lets look at an example: A pokémon that has both fire and water types <a href="https://bulbapedia.bulbagarden.net/wiki/Volcanion_(Pok%C3%A9mon">Volcanion</a><a href="https://bulbapedia.bulbagarden.net/wiki/Volcanion_(Pok%C3%A9mon))).">.</a></p><h4><strong>Volcanion’s Offensive Capabilities.</strong></h4><p><strong>Advantages</strong><br>Volcanion can potentially utilize moves from the fire and water pools giving it the potential to have a “super-effective” offensive advantage over 7 of the 18 other types.</p><ul><li>Fire has a x 2 advantage over bug, grass, ice and steel</li><li>Water has a x 2 advantage over fire, ground and rock.</li></ul><p><strong>Disadvantage</strong></p><ul><li>There are no types that are completely immune to either fire or water</li></ul><h4><strong>Volcanion’s Defensive Capabilities</strong>.</h4><p><strong>Advantages</strong></p><ul><li>The Fire and Water combo has no Immunities</li><li>Fire and Water combo has very good defense against fire, ice and steel types (If GoT had types)</li></ul><p><strong>Disadvantage</strong></p><ul><li>Fire and water combo has no significant weaknesses.</li><li>Electric and fround have the most affect but only up to a x2 multiplier.</li></ul><h3>“Now thats just wrong”</h3><p>The last consideration I am going to make when making type proposals is regarding if “Does this combo make sense.” Once again, I’ll use Volcanion whose Fire/Water combo does NOT make sense as they are polar opposites. However, Volcanion is a legendary pokémon so it can slide.</p><p>Types that are just wrong:</p><ul><li>Fire &amp; Water (Volcanion — <em>Legendary</em>)</li><li>Fire &amp; Grass</li><li>Fire &amp; Ice (George R.R. Martin — <em>Procrastinator</em>)</li><li>Dragon &amp; Fairy (Mega Alteria — <em>Mega Form</em>)</li></ul><p>I’m excluding the use of Mega pokémon and Legendary pokémon from my analysis as they are not standard, every day pokémon.</p><h3>Calculating Typing Balance</h3><p>I’ll be calculating values for all of the follows for every type combination in order to compare combinations that do not yet exist or are limited to those that does exist.</p><p><strong>Offensive Advantages</strong><br>Given a pokémon with a combination of two types, how many other types can this pokémon potentially have an offensive advantage over given its move pool? (aka super effective attacks)<br> <br><strong>Offensive Disadvantages</strong><br>Given a pokémon with a combination of two types, how many other types can this pokémon potentially have an offensive disadvantage over given its move pool? (“not very effective” attack or “doesn’t affect”). <br> <br> <br><strong>Offensive Power</strong><br>Given that it is this pokémon’s turn to attack, this is the sum of this pokémon’s <em>best</em> offensive attack multipliers per each opposing single type. Of the possible attack types, which has the best damage multiplier? If a water/flying type was battling a fire type, the water type moves would be best and that damage multiplier would be added to the offensive power summation. For this stat, higher is better.<br> <br><strong>Defensive Power</strong><br>Given how damage is calculated across a defending pokémon with two different types. What is the sum of damage distributed multipliers? There are 19 individual types, so if a pokémon’s type combination has no defensive advantages or disadvantages, and all attacks against do base damage, their Defensive Power will be 19 (1.0 * 19). For this stat, lower is better.<br> <br><strong>Defensive Advantages</strong><br>How many types of attacks are “not very effective” against this pokémon?<br> <br><strong>Defensive Disadvantages</strong><br>Which types of attacks are “super effective” against this pokémon?<br> <br><strong>Immunities</strong><br>Which types of attacks will have no affect on this pokémon?</p><p>I created a function to do the leg work which would take two-types as inputs and return information about the seven stat categories listed above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ik8ayifwlLfMOSXI6l20qg.png" /></figure><h3>Distribution Analysis</h3><p>Now that all that background information is taken care of, its time to start looking at some numbers. Below are histograms for the counts of offensive advantages and disadvantages for every pokémon that currently exists (excluding legendaries and megas).</p><p><strong>Offensive Advantages and Disadvantages</strong></p><p>We can see that most pokémon have 2 to 7 offensive advantages with 3 being the mode, 4 being the median and 3.8 being the mean. From this 4 is a good amount of offensive advantages, moving below that would make the pokémon weaker than average and moving above that would make it strong than average.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ini5VPW0od-BXzW1OYyAsA.png" /></figure><p>The distribution of offensive disadvantages is a little bit odd as the majority have about 3 disadvantages. We’ll still use 3 as our baseline as this is the median and mode and because there are a large occurrences of pokémon with 0 or 1 offensive disadvantages we can weight this category less severely.</p><p><strong>Defensive Advantages and Disadvantages</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lykG0zk8PFaL54N2dK-3Hw.png" /><figcaption><em>Please ignore the typo for the “disadvantages” plot.</em></figcaption></figure><p>Unlike the offensive advantages and “disadvantes”, we see distributions that are relatively flat with a very prominent mode. For the most part, a recommendation should have about 6 defensive advantages and 3 disadvantages; this is an example in which values deviating from the mode should be weighted more heavily.</p><p><strong>Offensive and Defensive Power</strong></p><p>The offensive power distribution is just all kinds of weird. The 18 to 19 range is quite sparse in observations, but it kind of makes sense if we look back on the offensive advantages distribution; it is probably better to use the summary stats to make a better judgment as far as what value should be considered the norm. Given the mean, median, and mode (20.4, 20, 19.5) 20 is probably a good norm, although it’s still pretty common to a higher offensive power.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L8jeuEleWtKNBTs7Sf8JLA.png" /></figure><p>Defensive power, on the other hand, exhibits some more consistency with a more obvious mode (18), however the mean (19) and median (18.75) are a bit higher, so 19 should probably be a better baseline.</p><h3>Weighting Deviation</h3><p>My initial idea was to use standard deviations of the original data in order to create acceptable ranges. However given that none of the data observed was normally distributed, I needed to instead interpret the distributions to find acceptable and unacceptable ranges for the above six features plus immunities. I created the below system of assignment:</p><ul><li>0 is representative of values around the norm (mean/median/mode) with negative values indicating.</li><li>Negative values are associated with weaknesses.</li><li>Positive values are associated with strengths.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ztis_l-nSj5oBcRwc0c37A.png" /></figure><p>After overwriting the original values with these subject matter engineered, values I used an equation similar to that of the standard deviation to understand how far a value is away from the average.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*sCxVxJFuSdz4l1_wZ2nHeg.png" /></figure><p>This equation took the v<strong>alue assigned </strong>(from the above table), the identified measure of c<strong>entral tendency</strong> for the feature (mean, median, mode or some combination of two) and the s<strong>tandard deviation</strong> of the actual feature (prior to the new value assignment). This equation calculates a deviation that has been re-weighted by the values I designed to assign based on my interpretation of the previous histograms.</p><p>One more thing is done with the newly assigned values, they are summed in order to come to a “<em>Balance Value</em>”, which will allow the positives and negatives of each feature to<em> balance out</em> for fair type-sets.</p><h3>Recommendations</h3><p>In the end, I used this “balance value” as a means of sorting the data to find the balance values closest to 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L6iKRNmzAWil5rNZ5lm9gA.png" /></figure><p>In the end, these first 10 recommendations are fairly decent:</p><p>A couple notes:</p><ul><li>I mentioned earlier that I would not recommend “Fire &amp; Ice” as that logically doesn’t make sense.</li><li>“Fairy &amp; Fairy” is a pure type fairy which I <em>know</em> exists and this seems to be the only accidental data leak on my part.</li><li>Other than that, most normal type pokémon that have another type have it as their secondary type and will be listed as “normal/fire”.</li></ul><p>There are some cool recommendations in there like “Dragon &amp; Electric”, “Poison &amp; Rock”, and “Bug &amp; Fighting” that I believe could be the starting point for some interesting pokémon. If I had any artistic talent, I would try to create some mock drawings of ideas that I have.</p><p>Heres the <a href="https://github.com/samuel-stack/The-Pokemon-Project">Accompanying GitHub Repo</a> for this project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c838a02f3d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Highly Recommend Scotch]]></title>
            <link>https://medium.com/@sam.stack/i-highly-recommend-scotch-21cd7173078a?source=rss-9b5276a5f34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/21cd7173078a</guid>
            <category><![CDATA[scotch]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sam Stack]]></dc:creator>
            <pubDate>Sun, 13 Jan 2019 02:01:24 GMT</pubDate>
            <atom:updated>2019-01-15T01:47:32.271Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FmhaJGBWM2o0leotbvZrIg.jpeg" /></figure><p>Scotch isn’t exactly the cheapest of spirits one can buy, in fact, its probably, on average, the most expensive with the majority of bottles being priced around $60-$80 and the upper end being in the thousands or even tens of thousands of dollars. That being said, most consumers of it want to know that if they are going to spend the equivalent of a week&#39;s worth of groceries on a bottle that they are going to enjoy it.</p><p><strong>This project was broken down into four major steps.</strong><br>1. Data Collection and Acquisition<br>2. Data Cleaning &amp; Exploratory Data Analysis<br>3. Data Preprocessing, Engineering and Transformation<br>4. Model Construction and Evaluation</p><p><strong>Data Collection and Acquisition</strong></p><p>Like any scraping or API centered project, I started by exploring the webpage and website structure of <a href="https://www.totalwine.com/">https://www.totalwine.com/</a> . Given that pages for each spirit and spirit list pages are relatively similar, I tried to make sure my scraping functions were universal and could be applied to other item groups on their website such as tequila or wine.<br>I typically utilize requests/BS4 combination for acquiring and parsing data while web scraping. The target website had some pop-ups to check for age the required me to also utilize Selenium in order to deal with. This proved to be useful in the long run as I needed to click ‘load more’ buttons in order to get all of the user review data.</p><p>This scraper worked by landing on the scotch homepage, then used some of the options available in the URL structure to filter the content returned. I could add details to the https request in order to better request and get the information I wanted. I used the following link in order to create the webpages in order to get all the scotch items listed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FDgltkp_I_1uye6iY25mDg.png" /></figure><p>I was able to filter the returned web page content to do the following.</p><ul><li>Full catalog of options (as opposed to those available)</li><li>Only bottle sizes of 750ml (standard) (<em>Not pictured, but would be `&amp;spiritsvolume=standard-size-750-ml`, prevented collecting duplicates based on size</em>)</li><li>Have 180 items returned per page (<em>limited number of web page requests to get all data</em>)</li><li>Sorted by name A to Z</li><li>Iterate through pages (I believe there were 8 in total).</li></ul><p>As number of observations gathered and associated amount of information about their item was small, I could store information in RAM, via a pandas dataframe, until all was collected. In hindsight, I wouldn’t recommend this “all or nothing tactic” as this scrape ended up taking about six hours. Probably a better Idea to deposit into a database or text file so if some issue occurs you just have to pick up where you left off.</p><p><strong>Quick Ethical Considerations</strong></p><ul><li>This data is to be used by the individual for the individual and not exploited to create any publicly facing application or revenue without the explicit permission from the owners of the data.</li><li>Put pauses in your scraper so you don’t have your IP blocked or overload the websites server. This is good for you and good for them.</li></ul><p><strong>Exploratory Data Analysis</strong></p><p>I started off by count vectorizing the taste notes data to better understand which words appear the most, the least and what terms have the strongest positive and negative correlations. Given that the taste notes listed on the website were often 3 to 5 adjectives in a list, the amount of data cleaning and text preprocessing prior to vectorization was very small(No stopword removal, stemmings or lemmatization needed). In addition tactics like Word2Vec would not provide any additional value.<br>After viewing with notes appeared the most (Rich, Balanced, Long, Spice &amp; Vanilla), I decided to look for correlation amongst notes to better understand which appear often together and which don’t seem to appear at all together.</p><p><strong>Common Combinations</strong><br>- “Cereal” &amp; “Grain”<br>- “Floral” &amp; “Fruit”<br>- “Blueberry” &amp; “Yeast”<br>- “Raspberry” &amp; “Hazelnut”<br>- “Seaweed” &amp; “Brine”<br>- “Mustard” &amp; “Seed” (Turned out the actual note was “Mustard Seed”</p><p><strong>Rare Combinations</strong><br>- “Long”, “Balanced” &amp; “complex”<br>- “Rich” &amp; “Delicate”, “Intense”, “Light” or “Medium”</p><p>“Mustard” &amp; “Seed” were perfectly correlated because the actual note is “Mustard Seed”; getting both as individual notes was a result of using an ngram size of 1. As a result I decided to remove the “seed” vector as a possible feature.</p><p><strong>Price vs. Score</strong></p><p>As some scotches can be quite expensive, we really start to see the effect of these as outliers when looking at the price. In my data collection, I acquired data for 131 scotches priced over `$1,500` and 64 priced above `$5,000`. Given this range and consistency of outliers, I looked at three separate ways of definitively labeling observations as outliers. Two utilized Tukey’s method and one used my personal preference.</p><ul><li>1. Q3($299.99) + 1.5 * IQR = $488.36</li><li>2. Q3($299.99) + 3 * IQR = $746.74</li><li>3. Personal Limit = $250 <em>This is probably the most I’d ever spend and I’d be extremely hesitant going anywhere near it.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3VRELH3HN-WgzzyheCTiOw.png" /></figure><p>As the majority of scotches fall in the $50 to $100 dollar range, I think using the 1.5 times IQR for outlier detection would have been fine as this was able to capture all scotches with prices less than $500, which in my opinion is ok, because if you want an overly expensive scotch you probably have money to burn or already have an idea of what you want and don’t need a recommendation. In addition, I said earlier that I was building this <em>for myself.</em></p><p>Now that I’ve talked about price, I imagine the next thing you want to know about is “does price influence ratings?”. To be honest, not really. The average user ratings for scotch showed a rather strange trend in that the majority of them were 4.9 stars or higher (35.9%). In addition, getting below a 3 star rating was very rare (4.9%). Based on that information I concluded that those users reviewing scotch, generally enjoy their scotch. The other insight that lead me to the conclusion that price doesn’t really influence how score was shown by my scatter plot comparing the two. In the scatter plot one can see that those few observations that score particularly bad(1-star) ranged from $50 to $300 a bottle. On the other side of the plot, we can see that bottles that received 5-stars ranged from $30 to $350 a bottle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*BGmPtyR7chPltAU_E_vlkA.png" /></figure><p><strong>Country</strong></p><p>Even though one of the qualifications in order to be considered “Scotch Whisky” is needing to be distilled and barreled in Scotland, I collected a handful of information on whiskey’s that had been categorized as scotch on the website from other countries such as Japan and India. I image the process used to create these whiskys is similar to that of making scotches and thus so they got grouped with them. Naturally, the idea would be to look and see if the country of origin has any relation to average user score, overall score or even the flavors that are most common <em>and</em> if this is a viable feature to include in the recommender system.</p><p>Before actually looking into that information I decided against using country in the recommender as it would potentially remove the adventure of being recommended a scotch-like whisky from Taiwan or France.<br>Pricing and scoring by country seems to be relatively similar to pricing and scoring as a whole so nothing interesting there. Probably the most interesting finding was that the three Asian countries who were the leading producers of these scotch-like whiskys, all had fruit appear in their top words leading me to believe that those consumers of whisky in Asian countries tend to enjoy more fruity tones.</p><p><em>The rest of the countries had 6 or fewer observations with many of those being incomplete making them not worth the time to look at more in depth.</em></p><p><strong>State</strong></p><p>Within Scotland there are five regions that scotches hail from. These regions have flavor profiles that are typically associated with the scotches that come from them. This is mainly due to the process and ingredients typically used in the region, such as Islay &amp; Islands being known for stronger peat and smoke flavors. (<em>Looking back, I should have looked at most prominent flavors based on state.</em>)</p><p>Knowing this breakdown of regions, I wanted to get a better understanding as to if a scotches region or origin influences its price or average user rating. Furthermore, not all regions have the same amount of observations ; Speyside : 338, Highland : 269, Islay &amp; Islands : 157, Lowland : 41, Campbeltown : 22</p><p>From looking at the violin plots of price based on state(below-left), Highland, Islay &amp; Islands and Speyside had very similar price distributions. Lowland looks like it has less of the more expensive scotches so its upper boundaries are shorter. Campbelltown had the smallest quartile range, mostly due to the fact that has the fewest observations out of all the regions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RKFAQnq9P-Mjn4ee4PmnTA.png" /></figure><p>Average rating distributions(above-right) for every region except Campbelltown were similar as well with Speyside and Lowlands having a few of the really bad reviews. Interestingly, Campbelltown had the highest median average rating and the smallest quartile range. While one can conclude that users tend to be much more satisfied with products from Campbelltown, the lack of observations could also be contributing to this insight (our sample isn’t relative to the population). <em>A t-test would have been a good idea to better understand if ratings based on region came from the same populations.</em></p><p><strong>Single Malt vs. Blended</strong><br> <br>For whatever reason I developed a bias perception of the differences between these two varieties without actually knowing anything about them. Naturally, I wanted to see if there was a difference in how they are perceived by others. <br>Single malts tended to be more expensive than blended, which makes sense. They also tend to be rated higher by the fact that there fourth/upper quartile can’t be seen (overlapped by the third). The median rating is also a bit higher as well. In addition to be rated at the top more often, they have more cases of being rated towards the bottom as their first quartile tail extends much further down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cfDW8jfxphJo2pQflpDVRA.png" /></figure><p><strong>Cosign Similarity Recommendation</strong></p><p>Given the EDA on taste notes, scotch variety and region, I decided to only user the taste notes in order to not exclude the possibilities of having something more “out there” or unique recommended. Since this recommender is for personal use, exploration into new things is important to me and I don’t want to have options brushed away because of their region of origin or that they are blended. The last feature I wanted to look at was price. Price is actually important to me, so I would like it factored into the model, the question is “how should it be represented?”.</p><p>As we observed, its not exactly normally distributed, however, I was able to make something a bit more normal by taking the log value. I looked at five separate ways of representing price ; ‘Price’, ‘Price Logged’, ‘Price Scaled’, ‘Price Scaled then Logged’ and ‘Price Logged then Scaled’. After reviewing results, I believed that Price Logged Scaled would make price too much of an important feature and lower priced scotches would be penalized in their ability to be recommended. Price Scaled Logged would remove too much of the importance of price and not make it as useful as a feature as I would have liked. In the end I settled on using the scaled price variable and adding a model argument that manually weighted the emphasis on price based on what value was passed to it.</p><p><strong>Recommendation</strong><br>In the end my similarity model used the taste notes, after being count vectorized and the Price Scaled feature and a weight that was provided with the input to indicate how important price was to the user. I choose Count Vectorization over Hashing or TFIDF as there are not duplicate words per observation and comparing on “is there” or “isn’t there” was really the only reasonable option.</p><p>The model also worked on averaging inputs so users could provide up to three scotches they enjoy and get a compromise recommendation of such. <br> I tested mostly on scotches that I enjoy (tending to be peaty and smoky) and scotches my coworker Nick enjoyed (Fruity and Spicy). These tests were conducted on the multi-input and single method. According to my multi input of Laphroaig 10 Yr., Laphroaig Quarter Cask and Lagavulin 16 Yr I should definitely check out Talisker 18 yr($149.99), Dalwhinnie Distillers Edition($76.99), Glenfiddich 12 Yr($26.99), Shieldaig Islay Single Malt($16.99) as these seemed to be consistent regardless of price weight. I also had a recommendation of Amrut Peated Single Malt($59.99) which peaked my interest as its from India.</p><p><strong>Conclusion</strong></p><p>All-in-All I am pleased with the results that are recommended. I have a lot of recommendations that I can sift through and try. I probably only buy a bottle of scotch once every one to two months so I have a list of recommendations to last me a year or so. <br> Unfortunately, since I’ve finished these set of recommendations I have only tried one of my recommendations, the ‘Shieldaig Islay Single Malt’($16.99), which in my opinion was excellent for its price. It had a bit of that alcohol sting towards the end of taste, but still very good for its price point.</p><p>Heres the list of Scotches I’m going to try to check out in the future. (two to three years worth)</p><ul><li>Amrut Peated Single Malt : <em>Based on Laph. 10, Laph. QC, Lag. 16</em></li><li>Ardbeg Uigeadail : <em>Based on Lagavulin 16 Yr</em></li><li>Berrys’ Ardmore 8yr : <em>Based on Laph. 10, Laph. QC, Lag. 16</em></li><li>Bowmore 12 Yr : <em>Based on Laphroaig 10 Yr.</em></li><li>Dalwhinnie Distillers Edition : <em>Based on Laph. 10, Laph. QC, Lag. 16</em></li><li>Deanston 12 Yr : <em>Based on Laphroaig Quarter Cask</em></li><li>Glenfiddich 12 Yr : <em>Based on Laph. 10, Laph. QC, Lag. 16</em></li><li>Glen Ness 12 Yr : <em>Based on Laphroaig Quarter Cask</em></li><li>Isle of Jura 16 Yr : <em>Based on Laphroaig 10 Yr.</em></li><li>Jura 10 Yr : <em>Based on Laphroaig Quarter Cask</em></li><li>Ledaig 10 Yr : <em>Based on Laphroaig 10 Yr.</em></li><li>Nikka Coffey Malt Whisky : <em>Based on Lagavulin 16 Yr</em></li><li>Talisker 18 Yr : <em>Based on Laph. 10, Laph. QC, Lag. 16</em></li></ul><p>Hope you enjoyed this and if you want additional details, here the <a href="https://github.com/samuel-stack/Whiskey-Recommender">git hub repo for this project!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21cd7173078a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scotch and Machine Learning]]></title>
            <link>https://medium.com/@sam.stack/scotch-and-machine-learning-3a990f6a26ab?source=rss-9b5276a5f34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a990f6a26ab</guid>
            <category><![CDATA[scotch]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Sam Stack]]></dc:creator>
            <pubDate>Fri, 11 Jan 2019 17:55:10 GMT</pubDate>
            <atom:updated>2019-01-11T17:55:10.659Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, about two-and-a-half years ago, I got into Data Science. More recently, about eight months ago, I got into drinking scotch. Most recently, I combined my interest in the two and created a simple recommendation engine to help me choose the next scotch I should try. Why did I do this? Scotch isn’t exactly a bottom shelf spirit, so for the few times a year I buy a bottle, I want to make damn sure I’m getting my moneys worth.</p><p>When I was working on the project, I gained a bit more subject matter expertise about scotch and I found out that there is a damn good correlation to making scotch and to making a machine learning model. Those elements that stuck out the most to me that I’m going to share with you today are ensemble methods, and errors due to bias and variance.</p><p>Lets take a look at Ensemble modeling first as this was the component that really set this light-bulb off for me.</p><p><strong>Blended Models and Ensemble Scotches</strong></p><p>Ensembling, with respect to Machine Learning, is the act of combining several individual models, either sequentially or in parallel in order to come to a single prediction/conclusion. The rational for their predictive power is based off of the concept of ‘wisdom of the crowd’, in which the collective guessing of a group is often more accurate than the individual guesses of its parts. Each individual model is expected to have its own strengths and weaknesses. These ensembles work best when each model’s weaknesses are unique so that the other models in the group can compensate for said weaknesses.<br>Another great element of ensembles is their ability to work with relatively non-complex models. The models that go into the ensemble can be, on their own, weak learners or just be mathematically simpler models such as decision trees, but still work extremely well as a whole.</p><p>Blended scotches are the scotch counterpart to ensemble methods. They too rely on aggregating several individual scotches with the intent of coming to a result that is stronger than any of the individual pieces. Like the models in the ensemble, these individual scotches are typically not as complex, in that they have not developed as intense of flavors and potentially have some impurities. Blending them however, allows for specific flavors to become more enhanced and any impurities to be neutralized.</p><p>One could also make a argument that a normal machine learning model is much like a single malt scotch, but I don’t feel like that is the best comparison we can make. I’m going to take a step back real quick and add some additional context. For most of us that do, consuming alcohol began in college with those bottom shelf spirits and sorry excuses for beer. Most of us also started learning about machine learning by being exposed to linear regression or k-neighbors models. In both situations these are the simplest things that managed to get the job done for the time being.</p><p>At this point in our lives/careers we’ve progressed away from those simplest means and have (hopefully) moved on to mediums that are considered more complex, which leads me to my next comparison; “A Single Malt is like Neural Network”.</p><p>When I was thinking through my “Ensemble to Blended” comparison, I couldn’t help but really think about what is the single malt analogy? The one component that stuck out to me the most about single malts was time. They gain their flavors from extended periods of aging, sometimes iterating through various different barrels and so the model that also gains the most through extensive aging and iterations are neural networks. Typically, the longer a neural network runs/back propagates(ages) the better it becomes, of course, the specifics why are different, but lets not let that discourage us from continuing. (You can also make the point that continuing to age scotch will almost alway increase its value and NNs typically converge and struggle to further reduce any error.) <br>To build off my point from earlier, nobody starts with neural nets or single malt scotches as they are not approachable without background understanding. They are perceived as complex and mysterious and they kind of are. Neural Nets and scotches are not for every day use and are typically brought out for special occasions.</p><p><strong>The Bias and Variance of Scotch</strong></p><p>Errors due to bias and variance are problems data scientists often face when building and evaluating their machine learning models. <br>Error due to variance is associated with a concept called “Overfitting”, which is the result of a model relying too much on the training data, resulting in the model not being great at generalizing on new information. The model performs well on data it has seen, but poorly on data it has not. Think of a student who studies the answers for a test, but not the concepts.</p><p>— Variances in the data, differences from what has been seen, result in wildly wrong predictions by the model.<br> — Typically a result of the model being too <em>complex</em>.<br> <br>Error due to bias is associated with a concept called “Underfitting”, which is the result of a model not using or not being able to use enough of the information available and does a poor job of generalizing on the data its seen as well as new data. This is the student who never studies and receives consistently poor test scores.<br> — Error due to bias(in the model) is observed with an underfit model.<br> — Typically a result of the model being too <em>simple</em>.<br> <br>There is one more important note about overfitting, underfitting, and errors due to bias and variance. Overfit models tend to have a greater variety in their predictions, yes they do tend to have predictions that are far closer to the true value, but they also have a tendency to have predictions that are sometimes wildly wrong. On the other hand, underfit models have a tendency to be less accurate with their predictions in general, but have more consistent errors.</p><p>Ok great, but how does this relate to scotch? Let me show you this review I found when building my scraper.</p><p>“<em>I don’t consider myself an expert but I have tasted many Scotches and this was horrible. To be fair I am a Speyside guy and prefer lower peat and smoke. This was a gift and sworn by so you can image my surprise when I had to choke down the first sip. I did come back to my whiskey bar the next day to try another sip and it wasn’t as bad as the first but I wasn’t giving it a third try. The smell was medicine like and the taste was heavy in smoke or ash.”<br> </em><br>This was a review for Lagavulin 16, which is a very popular and widely liked scotch. It is known for its intense smoke and peat and to be Ron Swanson’s scotch of choice, however clearly this user was not a fan. He’s not alone, but he is in the minority. Out of 71 reviews 61 are five-star and five are one-star. This review is what got me thinking that maybe, just maybe scotches could be prone to bias or variance. <br>Clearly, there are many users that enjoy the extreme flavors associated with Lagavulin 16, but there are also some that don’t and when they don’t, they really don’t. One could say that Lagavulin’s focus on intense smoke and peat made it an exceptional scotch for many consumers, but a wildly unpleasant scotch for a minority and thus a high variance scotch. A scotch the is high susceptible to individual user preferences.</p><p>On the other hand, what does a scotch that is bias look like(or the most that I could find)? Lets look at Glenlevit 12, which is also the first scotch I ever had. On <a href="http://www.totalwine.com/">www.Totalwine.com</a> this has 40 reviews, 14 five-star, 16 four-star, 8 three-star and 0 one-star reviews. People like it, they are hesitant to love it, but nobody hates it. While this isn’t the best representation of a high bias model it does exhibit some of the trends that are witnessed with high bias/underfit models. Firstly being that they can still be correct in some situations (5-stars); Second, there is consistency in errors (one can almost expect a 4 star review with a 1 star deviation); Thirdly wild inaccuracies(1 star reviews) are non-existent or extremely rare.</p><p>I guess the point of this post is that machine learning is more approachable and relative than what people may actually believe. The concepts we use everyday as data scientists are all around us, naturally occurring or just common knowledge and it really just takes a step back from someone that knows about both side to see the similarities.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a990f6a26ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>