<?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 Eugene Olkhov on Medium]]></title>
        <description><![CDATA[Stories by Eugene Olkhov on Medium]]></description>
        <link>https://medium.com/@eugeneolkhov?source=rss-ae6de64c7449------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tRR62GGgsizwj3fCNV9OLA.jpeg</url>
            <title>Stories by Eugene Olkhov on Medium</title>
            <link>https://medium.com/@eugeneolkhov?source=rss-ae6de64c7449------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 07:11:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eugeneolkhov/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[Top 3 things I learned from attending a cannabis conference]]></title>
            <link>https://medium.com/compassred-data-blog/top-3-things-i-learned-from-attending-a-cannabis-conference-77811d7ed0ff?source=rss-ae6de64c7449------2</link>
            <guid isPermaLink="false">https://medium.com/p/77811d7ed0ff</guid>
            <category><![CDATA[mjbizcon]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[cannabis-industry]]></category>
            <category><![CDATA[cannabis-testing]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Eugene Olkhov]]></dc:creator>
            <pubDate>Wed, 08 Dec 2021 14:24:42 GMT</pubDate>
            <atom:updated>2021-12-08T14:24:42.869Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QHRNb8s7aO4Q60sH7qzmxA.jpeg" /></figure><p>You’re going to a what?? This was the reaction from family members and friends when I told them I was going to Las Vegas for a cannabis business conference.</p><p>It’s important though to go back several months to get some context around how we ended up at the <a href="https://mjbizconference.com/">2021 MJBizCon</a>, and the beginning of my journey into the world of the science of cannabis.</p><p>There’s never a boring day at <a href="https://www.compassred.com/">CompassRed</a> due to the plethora of interesting clients we get to work with on a daily basis, and <a href="https://www.labware.com/lims/ml-ai">LabWare</a> is no exception. <a href="https://www.labware.com/lims/ml-ai">LabWare</a> is one of the global leaders in providing LIMS (Lab Information Management System) software to analytical laboratories across many industries. One of their newest offerings, LabWare GROW, is aimed at tailoring and providing their software to cannabis testing labs. LabWare GROW automates sample management from receipt to reporting while capturing data with a fully compliant audit trail. Our solution, <a href="https://www.compassred.com/orbis-lab">Orbis Lab</a>, provides LabWare GROW users with advanced analytics capabilities. With the tools we’ve developed together, laboratory managers are able to yield better insights about their operations and quality assurance practices using interactive visualizations and predictive insights (anticipate demand and instrument repair). We’re excited about the work as we see a big opportunity in the LIMS space for advanced analytics.</p><p>So, we got to work on learning everything there is to know about how different cannabis products are tested. I didn’t know too much about the area before this work, so it really opened my eyes to just how much goes into this, from the countless combinations of products, to the potential contaminants and variations in potency of strains.</p><p>While there’s plenty of information available online — nothing compares to talking to actual people working in the industry. When we were told that the biggest cannabis business conference was happening in Las Vegas, we knew this would be an incredible opportunity to learn more about the industry.</p><p>First, the atmosphere: it was energizing and it felt like everyone was there with a purpose. During the first day of the conference (out of the two full days we were attending), our booth at LabWare was getting non-stop traffic! While most people were curious about the software — many were interested in the car that was parked in the booth!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AjfHeRqBa3YCUIhn6h2V8g.jpeg" /><figcaption>LabWare CEO Vance Kershner’s “Hellrunner” — a 1973 Plymouth Roadrunner with a 2016 Dodge Hellcat with a slogan of “High Performance” to attract attention</figcaption></figure><p>While talking to prospective testing laboratory clients was informative, it was really the second day where we started to explore other booths and hear what others are doing in the industry. The floor space was huge and stretched multiple conference halls, with hundreds of booths. This definitely made it difficult to talk to everyone, but we were still able to talk to some interesting people.</p><h3>Environmental Monitoring</h3><p>We spoke with several companies that provide equipment to cannabis growers to monitor their plants. While growers send their samples to testing labs to check for contaminants, potency, and other factors, it’s important to have a step which keeps track of the growing conditions. Having this step would allow an analysis where we can start to understand why certain contamination happens, and what types of growing conditions lead to differences in potency. Ultimately, this provides us with an incredible opportunity to begin to predict when these things will occur, which can then allow for prevention of unwanted outcomes.</p><h3>Therapeutics</h3><p>Most people likely associate cannabis use with changing one’s mental state for (usually) recreational use, and sometimes to reduce pain / stress from illness. However, doing research into cannabis and attending this conference revealed just how many other therapeutic applications there are.</p><p>For example, there’s companies that are producing CBD infused gels which can be applied to joints topically for a targeted way to reduce pain.</p><p>There’s also research going into what types of cannabis strains help with specific ailments. Similarly, the key is having targeted ways to alleviate health problems. This is a really exciting development that can help people without requiring having to try multiple products, and minimizing any unwanted side effects.</p><h3>Booming Industry</h3><p>The third takeaway is simply just how much growth and opportunity exists in the cannabis space. This industry is still in its infancy — and yet is already showing so much potential and innovation with the wide range of vendors.</p><p>We had conversations with folks from cannabis-focused digital marketing agencies, cannabis cultivator apparel companies, cannabis-focused payment processors, agriculture monitoring system providers, cannabis podcasters, supply chain focused vendors, and more. Every part of the cannabis production process was covered in one way or another.</p><p>It’s surprising to see how many people there were actively researching, making purchases, and forming formal partnerships. There is urgency in the industry to move quickly right now so the energy was exciting all around.</p><p>Overall, attending this conference was an incredibly informative experience. The CompassRed team got the opportunity to dive in head first into this exciting industry and learn quickly.</p><p>We saw that the business needs we help meet for our current clients are similar to the ones we talked about with cannabis vendors at MJBizCon: “I need to reduce costs”, “I need to optimize my production process”, “I need to better attract new customers”. These statements underline the need for good data solutions for people making decisions in every industry.</p><p>We took a lot away from the experience and it allowed us to better understand the clients we’re developing software for in the cannabis space! We see a bright future where LabWare Grow clients are able to utilize Orbis Lab, and gain valuable, actionable insights. Thanks again to our partner LabWare for including us.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77811d7ed0ff" width="1" height="1" alt=""><hr><p><a href="https://medium.com/compassred-data-blog/top-3-things-i-learned-from-attending-a-cannabis-conference-77811d7ed0ff">Top 3 things I learned from attending a cannabis conference</a> was originally published in <a href="https://medium.com/compassred-data-blog">CompassRed Data Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Benefits of GPUs in Data Science and How I Taught Myself About Them]]></title>
            <link>https://medium.com/compassred-data-blog/benefits-of-gpus-in-data-science-and-how-i-taught-myself-about-them-2e766101645c?source=rss-ae6de64c7449------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e766101645c</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Eugene Olkhov]]></dc:creator>
            <pubDate>Wed, 24 Mar 2021 17:53:21 GMT</pubDate>
            <atom:updated>2021-03-24T17:53:21.047Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XwFF8dkOzx2Y4Taa" /><figcaption>Photo by <a href="https://unsplash.com/@christianw?utm_source=medium&amp;utm_medium=referral">Christian Wiediger</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>As a Data Scientist who has done his own fair share of model training, I’m very familiar with spending long periods of time waiting for training to finish, especially as you increase your data size and / or model complexity.</p><p>When training on a local machine, these long wait times become inconvenient not just because of the wait itself, but also because you will often be forced to keep your computer running throughout the night, or even multiple nights in a row. Hopefully, your computer doesn’t randomly restart due to an update! Besides the issues of running overnight, you also face the problem of your machine slowing down during the day while you attempt to work on other things.</p><p>It was not until I started working on a computer vision problem, that I finally decided that I need another method for model training. Given the prevalence of face masks, I was working on training a model to detect when a face mask was worn improperly. Using my standard method of model training, the model would have taken over 24 hours to train. This is not a feasible training time especially when you consider needing to make tweaks to the model. Training times need to be relatively fast in order to properly iterate on the model.</p><p>So, what’s the solution? Clearly, as problems become more difficult, and models become more advanced, we can’t keep running things on our local machines, right? Sort of.</p><h3>Cloud Computing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iTAEr_NVnAvPkLvz50bBmg.png" /></figure><p>The easiest solution is to switch from your local machine, to a virtual one. You can create an account with Google Cloud Services (GCP), Microsoft Azure, Amazon Web Services (AWS), Digital Ocean, etc. Once you have an account, you can either setup a free virtual machine instance or a paid one. The free instance usually doesn’t have enough power to do any serious model training, but it’s good to use to get familiar with the service. Keep in mind, if this is your first time setting up an account, many services give you some free credit to use on the paid instances.</p><p>This solves the issue of needing to keep your local machine running, but also you can customize your virtual instance to be a lot more powerful than your local machine which will speed up your training time. You can also utilize a virtual GPU instance, which, as I will cover next, will speed up your training immensely. Of course with great power, comes a big price tag. The more powerful your virtual instances are (especially vGPUs), the more you’re going to pay. Of course, if this model is going to be part of your core business, then it’s just going to be part of your business expenses. However, what if this is your personal project, or maybe a proof-of-concept where you don’t want to spend that much money on resources (yet). In that case, setting up training on a local GPU might be worth your while.</p><h3><strong>Setting up a local GPU</strong></h3><p>The main caveat is you need to have your own NVIDIA GPU. You could also buy one, but depending on the GPU, it can get quite pricey. Of course, if you envision yourself using it a lot then it would be worth it. If you’re not sure you have an NVIDIA GPU on your local machine, you can check the device manager on Windows, or the “About This Mac” &gt; Display if you’re using a Mac.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*z0KvusePIlQ1jFVmUMVJbg.png" /></figure><p>The nice thing is that you don’t actually need to have a high-end GPU. The GPU in my laptop is on the lower end, and I was still able to see large improvements in training speed.</p><p>Ideally, you would also want to set this all up on a Linux machine. The process appears to be relatively straight-forward and involves installing the relevant drivers from NVIDIA. However, I am working on a Windows machine so my process was a bit different.</p><p>To make things even more complicated, my workflow also consists of working out of a Linux-based Docker container using Docker Desktop which adds some complexity in the setup process.</p><p>Luckily, I was able to find this helpful <a href="https://www.docker.com/blog/wsl-2-gpu-support-is-here/">post</a> which explained the steps I needed to take in order for Docker to be able to communicate with my GPU. The key steps are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PfM0ep40dSepLHK56-xz9A.png" /></figure><p>While initially the steps seemed to be quite simple, there was one step in particular which at first I overlooked: Windows Insider. As I quickly learned, this actually involved installing a developer preview version of Windows on my machine. At first, I was a little reluctant to do so given that it could affect stability / compatibility of my machine, but since all the other methods I tried failed, I decided to go for it.</p><p>At first, the update actually failed! My machine then reverted back to the original version of Windows that I was on. However, since my settings were still set to the dev version of Windows, the next time I restarted my machine, it successfully installed the preview software.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JN5JTPcd2mq3mTey2xeTnQ.png" /><figcaption>The windows version should look something like this if successful</figcaption></figure><p>Once this happened, I spun up a Docker instance, and ran some simple benchmarks which revealed that Docker was communicating with my GPU!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*BJOe4yYDGpwY3Cpdv8CIJA.png" /><figcaption>Results of the benchmark listed in the Docker blog post linked above</figcaption></figure><p>One last step that I needed is to make sure it was working with the Jupyter Notebook instance inside the container. For this, I needed to make sure my Dockerfile contained all the proper NVIDIA drivers, so that when I built my image, everything could communicate with each other.</p><h3>Benefits</h3><p>Now that I was able to set this all up, does it actually improve my training speed?</p><p>Yes, definitely!</p><p>My training speed was about 3x faster, even with my low-end GPU. These are important findings, especially given that the CPU that I was using to train previously is a quite powerful i9 8th gen core. High-end GPUs are expected to have an even greater improvement of 10x+ the speed!</p><p>So, when should you use a GPU to train vs a CPU? At a very high level, GPUs are very good at doing a large number of small tasks quickly, where as CPUs are good at doing a small number of hard tasks. There’s obviously a lot more nuance there, but the key is that GPUs are ideal for deep learning tasks where in order to train the model, there’s a huge number of small calculations that need to happen.</p><p><strong>Disclaimer</strong></p><p>There is a lot of variation in the workflows that people use, and the process I outlined here has worked for me, as someone who has not had previous experience in utilizing GPUs in my work. It’s quite possible that there is a more simple solution that will work for you, but hopefully this has provided some general knowledge to allow you to either use this method, or find your own.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e766101645c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/compassred-data-blog/benefits-of-gpus-in-data-science-and-how-i-taught-myself-about-them-2e766101645c">Benefits of GPUs in Data Science and How I Taught Myself About Them</a> was originally published in <a href="https://medium.com/compassred-data-blog">CompassRed Data Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Three More Ways to Make your RMarkdown Better]]></title>
            <link>https://medium.com/compassred-data-blog/three-more-ways-to-make-your-rmarkdown-better-de4f391256de?source=rss-ae6de64c7449------2</link>
            <guid isPermaLink="false">https://medium.com/p/de4f391256de</guid>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[markdown]]></category>
            <category><![CDATA[rstudio]]></category>
            <dc:creator><![CDATA[Eugene Olkhov]]></dc:creator>
            <pubDate>Thu, 28 Jan 2021 16:10:09 GMT</pubDate>
            <atom:updated>2021-01-28T16:10:09.534Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hyj8RIFrNjZ5RScV-MCSOA.png" /></figure><p>Several months ago, I published <a href="https://medium.com/compassred-data-blog/top-3-things-to-make-your-rmarkdown-better-part-1-a137f78315b9?source=friends_link&amp;sk=abe31e58dea345e4e16aff3f538830b0">an article</a> which covered 3 simple ways to improve your RMarkdown. In this sequel article, I want to cover 3 more ways to improve your RMarkdown which deal with slightly more advanced techniques.</p><h3>1. Adjusting CSS</h3><p>In the previous <a href="https://medium.com/compassred-data-blog/top-3-things-to-make-your-rmarkdown-better-part-1-a137f78315b9?source=friends_link&amp;sk=abe31e58dea345e4e16aff3f538830b0">article</a>, I covered using built-in themes. These are really easy to use, and require a single line of code in the YAML of the RMarkdown. However, what if you want to modify a specific part of the theme such as the colors or font for a specific section? Here’s how you can do that:</p><ol><li>First, visit <a href="https://bootswatch.com/3/">Bootswatch </a>and look for the theme you want. This will have the built-in themes that are available in RMarkdown.</li><li>Download the bootstrap.css file associated with your theme — use the arrow dropdown to choose the right file.</li><li>Make modifications to the .css file using your preferred method.</li><li>In the YAML, include the following:</li></ol><pre>output:<br>  html_document:<br>    css: your_css_file_name.css</pre><p>Once you have added it, it will behave exactly the same as the default theme, but will incorporate the changes you made.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x6wyjN285KpeeuvwMV1_EQ.png" /><figcaption>Original theme “United”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6rawd6tstQofr-7hPs77Aw.png" /><figcaption>Modified background color</figcaption></figure><h3>2. Adding a logo</h3><p>Often, you want to customize your RMarkdown with some branding. Here at <a href="https://www.compassred.com/">CompassRed</a>, we like to include our company logo at the top of the document. This can be done using a variety of ways. Typically, we do this by adding a short jQuery snippet right after the YAML like so:</p><pre>---</pre><pre>&lt;script&gt;<br>  $(document).ready(function() {<br>    $(&#39;#section-TOC&#39;).parent().prepend(&#39;&lt;div id=\&quot;nav_logo\&quot;&gt;&lt;img src=&quot;logo_name.svg&quot;&gt;&lt;/div&gt;&#39;).css({&quot;padding-top&quot;: &quot;25px&quot;});<br>  });<br>&lt;/script&gt;</pre><pre>---</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*lLAB2R1U0dSGUTt5VoxBrQ.png" /></figure><p>The above can be customized in a variety of ways. We prefer our logo to sit on top of the table of contents in the top left corner.</p><p>The #section-TOC ID is the container for the table of contents. If you prefer the logo somewhere else, find the ID of the container you’re looking to target and input it into the jQuery (might take some modification of the parent function).</p><p>This code also assumes that the svg file of the logo exists in the same folder as the output html file. Alternatively, you can host the image somewhere and reference it in the src. This would be useful in instances where you need to host the output html file somewhere.</p><h3>3. Chunk options</h3><p>Finally, utilizing chunk options is another great way to customize your RMarkdown. There are many of these options that you can utilize. I will cover a few ways I personally use chunk options, but definitely check out the following <a href="https://bookdown.org/yihui/rmarkdown-cookbook/chunk-options.html">source</a> for ones I don’t mention.</p><p>Code folding is something that was briefly mentioned in the <a href="https://medium.com/compassred-data-blog/top-3-things-to-make-your-rmarkdown-better-part-1-a137f78315b9?source=friends_link&amp;sk=abe31e58dea345e4e16aff3f538830b0">previous article</a>. It’s useful if you are sharing your RMarkdown with different types of audiences, some of which may be interested in seeing your code. Code folding makes that easy by providing input buttons to either show or hide code. However, if you’re sharing with an audience that you know has no interest in seeing the code, you can omit the code output from individual chunks using the echo = F option.</p><pre>{r, echo = F}</pre><p>Alternatively, you can set the argument to TRUE if you want to force the code to be seen. You can also ignore warnings and messages if you would like. This is useful in the chunk which imports libraries since there’s often a lot of output that you wouldn’t want to clutter the document.</p><pre>{r, echo = F, message = F, warning = F}</pre><p>The final chunk option that I often use myself is setting figure sizes. Frequently, I find that the default aspect ratio of my ggplot2 visualizations isn’t quite how I want them to appear. For example, sometimes I want the viz to be wider in the output RMarkdown. For this I use the following:</p><pre>{r, fig.width = 10, fig.height = 5}</pre><p>The above gives me a 2:1 aspect ratio which usually works well. However, I encourage you to try out different sizes to see what works best for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UZIFLpIlH9xXaiCFrYkFFQ.png" /><figcaption>This is using an aspect ration of 5:7</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7bMowXlSMkkxPWCed7MUdw.png" /><figcaption>This is using a wider aspect ratio of 2:1</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de4f391256de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/compassred-data-blog/three-more-ways-to-make-your-rmarkdown-better-de4f391256de">Three More Ways to Make your RMarkdown Better</a> was originally published in <a href="https://medium.com/compassred-data-blog">CompassRed Data Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top 3 Things To Make Your RMarkdown Better (Part 1)]]></title>
            <link>https://medium.com/compassred-data-blog/top-3-things-to-make-your-rmarkdown-better-part-1-a137f78315b9?source=rss-ae6de64c7449------2</link>
            <guid isPermaLink="false">https://medium.com/p/a137f78315b9</guid>
            <category><![CDATA[r-markdown]]></category>
            <category><![CDATA[reporting]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[r]]></category>
            <dc:creator><![CDATA[Eugene Olkhov]]></dc:creator>
            <pubDate>Wed, 16 Sep 2020 15:04:48 GMT</pubDate>
            <atom:updated>2020-09-16T16:18:15.512Z</atom:updated>
            <content:encoded><![CDATA[<h3>Top 3 Ways To Make Your RMarkdown Better (Part 1)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*asykzmJZlg0b7otN.jpg" /><figcaption><a href="https://rstudio.com/about/pbc-report/">Source</a></figcaption></figure><p>Last month I talked about the <a href="https://medium.com/compassred-data-blog/how-to-host-and-share-rmarkdown-files-cc8474893818">multiple ways of sharing RMarkdown analyses with your target audience</a>. When you’re sharing your RMarkdown analysis, the most important aspect is the content itself, but formatting and aesthetic of the analysis is not far behind.</p><p>In this article, I am going to show you three simple things that can turn your analysis from a bland, flat file into a well organized, interactive document that people will want to read.</p><h3>1. YAML Settings</h3><p>The YAML section in an RMarkdown file is the very first section of code you see:</p><pre>---<br>title: &quot;Analysis&quot;<br>output: html_document<br>---</pre><p>The above YAML is at the most basic level, which just lists the title of the document (this shows up at the top when knitting/rendering), and then the output format. However, there are a huge amount of options that the YAML can take to help customize your document. Some of the ones I find most useful are using built-in themes, creating a table of contents and controlling code folding.</p><p><strong>Built-in Themes</strong></p><p>Using built-in themes is the easiest way to completely change the look of your entire document. This controls accent colors, font, and more.</p><pre>---<br>title<strong>:</strong> &quot;Analysis&quot;<br>output<strong>:</strong><br>  html_document<strong>:</strong><br>    theme<strong>:</strong> yeti<br>---</pre><p>The following themes are available: default, cerulean, journal, flatly, darkly, readable, spacelab, united, cosmo, lumen, paper, sandstone, simplex, and yeti.</p><p><strong>Table of Contents</strong></p><p>Another very useful option that can be added to the YAML is to include a table of contents. The code looks like this:</p><pre>---<br>title<strong>:</strong> &quot;Analysis&quot;<br>output<strong>:</strong><br>  html_document:<br>    theme: yeti<br>    toc: TRUE<br>    toc_float: TRUE<br>---</pre><p>This creates a table of contents on the right side of the document which lets you click on any section of the document to skip through. I particularly like using the float option as this makes the table of contents cleaner by only showing you the current section, but letting you scroll through the other sections. The sections are created by using different level headers ( # vs. ##, vs. ###…etc.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*_1SJi6-jUYkdODH_h1WNtA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*vw2Js5TRYYEFAsMODilVyA.png" /></figure><p><strong>Code Folding</strong></p><p>Code folding is another useful feature in case you want some of your target audience to be able to view the code which generated your analysis. The YAML option creates a clickable button at the beginning of the document to either show or hide all of the code:</p><pre>---<br>title<strong>:</strong> &quot;Analysis&quot;<br>output<strong>:</strong><br>  html_document:<br>    theme: yeti<br>    toc: TRUE<br>    toc_float: TRUE<br>    code_folding: hide<br>---</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/204/1*kIJ6X0kJa22haLqAoWpVNg.png" /></figure><h3>2. Tabset</h3><p>Often, in your analysis you will be creating multiple variants of plots, tables or other items used for comparison. These can quickly cause clutter, and make the document a lot longer than it needs to be.</p><p>Something that has completely changed my analyses is adding a tabset option for document sections which I want to collapse into a set of tabs. To make it work, create a header (let’s use a level 2 header for example). Under that header, create a few sub-headers (these are the items that will be collapsed into tabs).</p><pre>## Demographics {.tabset}</pre><pre>### Plot 1</pre><pre>&quot;Insert Plot 1 here&quot;</pre><pre>### Plot 2</pre><pre>&quot;Insert Plot 2 here&quot;</pre><pre>### Plot 3</pre><pre>&quot;Insert Plot here&quot;</pre><p>The results look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*Hbbf870KQrTNVqpwYw2cTQ.png" /></figure><h3>3. Plotly</h3><p><a href="https://plotly.com/r/">Plotly</a> is an interactive graphing library that allows for creating some really impressive interactive visuals. In order to get the best results, I would recommend using the syntax specific to Plotly. However, the Plotly package contains a ggplotly function which can take a ggplot object and make it interactive. While there are occasional bugs with this method, the ease of not needing to learn new syntax makes it worth it for many situations.</p><p>Here’s an example plot using just ggplot2 :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a8oThrjLR5tccA2kVJ0OeA.png" /></figure><p>Now here is an example of the exact same plot, but wrapping it in a ggplotly function. I can hover my mouse over each individual point, and get the data associated with it. It also has a capability for zooming in closer to a set of points by just drawing a shape around the points you want to investigate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*om870Xm6AoCZDSlDDSy2wA.png" /></figure><p>There are also some arguments that can be tweaked inside the ggplotly function. The documentation can be found <a href="https://plotly.com/ggplot2/">here.</a></p><p>These few examples will take your RMarkdown reports to the next level, but stay tuned for some more advanced techniques coming soon!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a137f78315b9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/compassred-data-blog/top-3-things-to-make-your-rmarkdown-better-part-1-a137f78315b9">Top 3 Things To Make Your RMarkdown Better (Part 1)</a> was originally published in <a href="https://medium.com/compassred-data-blog">CompassRed Data Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Host and Share RMarkdown Files]]></title>
            <link>https://medium.com/compassred-data-blog/how-to-host-and-share-rmarkdown-files-cc8474893818?source=rss-ae6de64c7449------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc8474893818</guid>
            <category><![CDATA[r-programming]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[rstudio]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[r-shiny]]></category>
            <dc:creator><![CDATA[Eugene Olkhov]]></dc:creator>
            <pubDate>Wed, 22 Jul 2020 13:45:25 GMT</pubDate>
            <atom:updated>2020-07-22T13:45:25.556Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/794/0*23hpOYfB_avreODG.png" /></figure><p>When I first learned how to use <a href="https://rmarkdown.rstudio.com/">RMarkdown</a>, I was in absolute awe. Moving from copy/pasting SPSS output into Word documents, to being able to automatically generate a rich analysis report full of text and visualizations at the press of a button was game-changing. RMarkdown files can also be rendered into a variety of formats which not only covers HTML, but also PDFs, Word documents, and others. While sharing an output file is easy and works great for an analysis that is conducted once, what if there are frequent updates that you want to share with clients/colleagues/others?</p><p>In the case that an analysis gets updated, it is not ideal to constantly be emailing various versions of the output file. This quickly becomes messy and unorganized. Plus, as the analyst you have to be spending time sending the output file. This can be especially troublesome if you’re looking to share the analysis with a large group.</p><p>One solution to this problem is to host your file on a server or website. You can choose to organize the files, or even overwrite the old analysis so that people viewing are always viewing the most up-to-date file.</p><h3>Shinyapps.io</h3><p>While there are many ways to host files online, our current favorite method at <a href="https://www.compassred.com/">CompassRed</a> is using <a href="https://www.shinyapps.io/">shinyapps.io</a>. This is a service that is offered by RStudio, and as the name suggests, mainly deals with hosting RShiny apps. RShiny is an incredibly flexible framework for building various types of web apps. Initially, we started using the service to host the apps that we have been developing. For example, check out this awesome <a href="https://compassred.shinyapps.io/ncco_biobot/">dashboard</a> that my colleague <a href="https://medium.com/@benalytics">Ben Kates</a> built for <a href="https://www.nccde.org/">Delaware’s New Castle County</a>. This dashboard displays the data collected by <a href="https://www.biobot.io/">Biobot Analytics</a> on the number of <a href="https://www.wdel.com/news/results-from-mit-programs-wastewater-study-provide-insight-into-covid-19-spread-in-new-castle/article_d8691c98-c2c8-11ea-878c-afdbdc91d221.html">COVID-19 samples found in wastewater.</a></p><p>While there is a bit of a learning curve to start using RShiny, you can use shinyapps.io to host your existing RMarkdown files as well. The service also makes it easy to make updates to the hosted file right from your work station. Here’s how to do it!</p><ol><li>First, you need to create a new account on <a href="https://www.shinyapps.io/">shinyapps.io</a>. There’s a free tier, as well as paid tiers with the main difference being number of active hours and performance.</li><li>Once your account is created and you are logged in, you will have to obtain a token in order for RStudio to be able to connect to your account and make publishing (RStudio’s language for deploying/hosting) seamless. Follow these two screenshots, and copy the code that is shown:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EmONgBdcyCIa_kxU.png" /><figcaption>Source: <a href="https://shiny.rstudio.com/articles/shinyapps.html">https://shiny.rstudio.com/articles/shinyapps.html</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mnXK8uGOoXiZNQmZ.png" /><figcaption>Source: <a href="https://shiny.rstudio.com/articles/shinyapps.html">https://shiny.rstudio.com/articles/shinyapps.html</a></figcaption></figure><p>3. Once you have saved the above code, open up RStudio and install/load the following package: install.packages(&#39;rsconnect&#39;);library(rsconnect). Then run the code you copied, and your account should now be linked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oC1mitSN9-QP00nX-K2BPQ.png" /></figure><p>4. Once you’re ready to host your RMarkdown file, add the code runtime: shiny to the YAML. This essentially turns your markdown into a shiny app. Click the publish button (in the blue box above), and that will let you set the name of the app, as well as any files you want to include. Since your markdown will be rendered by shinyapps.io, you will want to include all the files that you need such as data, functions, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Q0UHfsirdcjRuPcpY320w.png" /></figure><p>That’s it! You should now see the name of your app in the shinyapps.io applications dashboard. You will have all of the information you need, and to access the analysis/app just follow the link that is given in the shinyapps.io dashboard. Typically, this follows for the format of :[accountname].shinyapps.io/[app_title].</p><p>As mentioned above, one really great benefit of hosting your RMarkdown file this way is being able to update the analysis very easily. Since you’re able to publish as frequently as you want, whenever there’s a new update to the analysis, you can re-publish and the hosted app will update accordingly.</p><h3>Caveats</h3><p>While shinyapps.io has a free tier which can allow you to start using this quickly, it is worth mentioning the limitations.</p><p>The free tier contains 25 “active hours” per month. When no one is accessing an app, it is considered “sleeping”, and does not use up any active hours. However, once someone goes to the app link, it becomes active and starts to use up the active hours. If people are going to be accessing the app continuously, the 25 hour allotment will run out by the next day and you will not be able to use the service until the following month. The free tier allows you to create up-to 5 separate apps, but the 25 hours is the limit across all apps. Essentially, the free tier allows you to learn how to use the service but it is recommended to move up to a paid tier in order to use the service on a larger scale. The pricing of the different tiers is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LBhmRlk3aj8oU42tgwaPjQ.png" /></figure><p>Another caveat is regarding access and authentication. As seen above, only the two most expensive plans have authentication for apps built-in. For any of the cheaper plans, you will have to use your own authentication method, otherwise all of your apps will be public.</p><h3>Rpubs</h3><p><a href="https://rpubs.com/about/getting-started">Rpubs</a> is a completely free alternative if you only want to host RMarkdown files. This requires you to knit (create an html file) first, and then publish the file on Rpubs.</p><p>The limitations with this method is that you lose out on potential features such as being able to add authentication since anything on Rpubs is completely public. There are also things you can do on shinyapps.io such as incorporating parameters and other UI elements. Finally, with shinyapps.io, you can incorporate RShiny apps right in an RMarkdown which is not something you can do with Rpubs since it just hosts the html file. Stay tuned for an overview of some of the above features in future posts!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc8474893818" width="1" height="1" alt=""><hr><p><a href="https://medium.com/compassred-data-blog/how-to-host-and-share-rmarkdown-files-cc8474893818">How to Host and Share RMarkdown Files</a> was originally published in <a href="https://medium.com/compassred-data-blog">CompassRed Data Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Our Favorite Kaggle Kernels using COVID-19 Datasets]]></title>
            <link>https://medium.com/compassred-data-blog/our-favorite-kaggle-kernels-using-covid-19-datasets-d9f8e78caf52?source=rss-ae6de64c7449------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9f8e78caf52</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[covid19]]></category>
            <category><![CDATA[kaggle]]></category>
            <category><![CDATA[r]]></category>
            <dc:creator><![CDATA[Eugene Olkhov]]></dc:creator>
            <pubDate>Wed, 01 Apr 2020 13:49:05 GMT</pubDate>
            <atom:updated>2020-04-01T13:49:05.886Z</atom:updated>
            <content:encoded><![CDATA[<p>A couple of weeks ago, a collaboration of various <a href="https://pages.semanticscholar.org/coronavirus-research">research groups</a> released a huge dataset of literature which can be used to gain insights into the current COVID-19 pandemic. Additionally, Johns Hopkins updates a <a href="https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/csse_covid_19_time_series">dataset</a> that tracks confirmed cases/fatalities/recoveries daily. A call to action to the data community was given to help join the fight against the virus.</p><p>Two competitions were created on <a href="https://www.kaggle.com/allen-institute-for-ai/CORD-19-research-challenge">Kaggle</a>, and many people started to share their take on working with the data-sets and the different things that they have uncovered. We at <a href="https://www.compassred.com/">CompassRed</a> have been fascinated with a lot of the work shared. Here are our favorites so far from each of the competitions.</p><h3>1. <strong>COVID Global Forecast: SIR model + ML regressions</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*koWEWkCYFEVsf8GO7WRLqA.png" /></figure><p>The <a href="https://www.kaggle.com/saga21/covid-global-forecast-sir-model-ml-regressions">first kernel</a> was published by <a href="https://www.kaggle.com/saga21">Patrick Sánchez</a>, which utilized the Johns Hopkins dataset linked above.</p><p>This is a fantastic Python notebook that is updated frequently by the author. It contains a thorough exploration of the current trend of the virus across different countries and provides a good overview of the recent history.</p><p>The first attempt at forecasting future cases by the author is to use an SIR (Susceptible, Infected, Recovered/Deceased) model. This is a well known model in the epidemiology field that simulates how a virus in general will behave in a population given the contagion and recovery rates. This is covered more in-depth in the notebook, and shown how to calculate the values and create the model.</p><p>Following the SIR model, the author utilized a regression approach. Lag and date-based variables were created in order to turn this into a time-series problem, as well as some data enrichment by joining information about all of the countries. While predictions were not bad in the beginning for many of the countries, they decayed very quickly as predictions stretched farther into the future. In order to remedy this, the author took the early predictions and fed them back into the training data which improved the results by a large margin.</p><p>Highly recommended to check this kernel out!</p><h3>2. <strong>CORD-19: Explore Drugs Being Developed</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X4BM7jxijFewe2ro2FDUBw.png" /></figure><p>This <a href="https://www.kaggle.com/maria17/cord-19-explore-drugs-being-developed">second kernel</a> used the literature dataset, attempting to uncover effectiveness of drugs being used and developed to treat COVID-19 patients. The literature consists of over 29,000 scholarly articles related to different coronaviruses. Out of these, approximately 14,000 contain full texts.</p><p>The key part of this analysis is the authors used NLP (Natural Language Processing) techniques to uncover correlations between different molecular structures of drugs. They then were able to connect to the public <a href="https://www.ebi.ac.uk/chembl/">CHEMBL</a> database in order to search for drugs that are already similar to the ones mentioned in the current literature.</p><p>This type of work is a great first step into making sure that researchers can quickly find key information on drugs being considered to be used for treatment without having to spend hours on going through reading papers manually.</p><h3>Bonus</h3><p>While not a Kaggle kernel, an excellent resource for an overview of the literature dataset is <a href="https://youtu.be/-5HYdBq_PTM">David Robinson’s Screencast Series</a>:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F-5HYdBq_PTM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D-5HYdBq_PTM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F-5HYdBq_PTM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/db45abdc1ffb5cfbac9398bd0c28628f/href">https://medium.com/media/db45abdc1ffb5cfbac9398bd0c28628f/href</a></iframe><p>In the screencast, David shows how to ingest the data and conduct exploration in R. David also utilizes the <a href="https://allenai.github.io/scispacy/">scispaCy</a> package which contains a dictionary of medical terminology which makes the NLP tasks he conducts more meaningful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9f8e78caf52" width="1" height="1" alt=""><hr><p><a href="https://medium.com/compassred-data-blog/our-favorite-kaggle-kernels-using-covid-19-datasets-d9f8e78caf52">Our Favorite Kaggle Kernels using COVID-19 Datasets</a> was originally published in <a href="https://medium.com/compassred-data-blog">CompassRed Data Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[R vs Python, why not both?]]></title>
            <link>https://medium.com/compassred-data-blog/r-vs-python-why-not-both-91a78d74a0da?source=rss-ae6de64c7449------2</link>
            <guid isPermaLink="false">https://medium.com/p/91a78d74a0da</guid>
            <category><![CDATA[r]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[rstudio]]></category>
            <category><![CDATA[analytics]]></category>
            <dc:creator><![CDATA[Eugene Olkhov]]></dc:creator>
            <pubDate>Wed, 11 Mar 2020 15:50:30 GMT</pubDate>
            <atom:updated>2020-03-11T15:50:30.235Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/739/0*wcSAKIE9QwJt-nAc.png" /><figcaption><a href="https://rstudio.github.io/reticulate/">Source</a></figcaption></figure><p>The topic of whether to choose R or Python for data science work has been debated ad-nauseam. There are already <a href="https://www.datacamp.com/community/tutorials/r-or-python-for-data-analysis">countless</a> <a href="https://www.kdnuggets.com/2015/05/r-vs-python-data-science.html">articles</a> <a href="https://blog.rstudio.com/2019/12/17/r-vs-python-what-s-the-best-for-language-for-data-science/">discussing</a> the pros and cons of both, so I won’t go into too much detail in this post. While there is still a large debate on what to use between R and Python users, many agree that R is superior for data cleaning, exploration, and conducting general statistical analyses, while Python is more capable when it comes to developing and implementing models.</p><p>Given these main pros of R and Python, is there a way where we can utilize both languages in a project? Definitely!</p><p>One way to combine the two languages in your workflow is to do cleaning/exploration/transformation in R, write the results back to a database (or save the data in some other way), and then import the data into Python to build models.</p><p>This method should work, but what if you want to do this all in the same notebook to have the ability to go back and forth between R and Python? For this, you can use the reticulate package in R, while not fully robust, does a good job at converting R objects to Python, and vice versa.</p><h3>Running Python within RStudio</h3><p>RStudio has the capability to run Python code inside of RMarkdown without needing external libraries. It’s really simple to do (assuming you already have a version of Python installed on the same machine), just create a new chunk and replace the r with python as below, and you’re ready to run!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*n-yPNiXqbPAn0QJu_CLAJg.png" /></figure><p>The benefit of using the reticulate package though, is that it allows for conversion of R objects to Python and vice versa when possible. For example, if you’re cleaning some data in R and your data resides in a dataframe, when you switch to a Python code chunk, reticulate can be used to convert the dataframe in R to a pandas dataframe to be used in Python like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*MArUXcQKOAaIml9r_oAEJg.png" /></figure><p>In order to access something from the R environment in a Python chunk, you need to call r[&#39;object_name&#39;]. If you need to do the opposite, and access something from the Python environment in R, you can call py$object_name.</p><p>That’s essentially it! You can now use this workflow to (mostly) seamlessly switch between R and Python to your heart’s content. However, there are some cons to using this workflow.</p><h3>Cons</h3><p>While I was VERY excited (ask my co-workers) when I got this working, after using this workflow for a few days, I realized that it’s not quite there yet.</p><p>First, it takes a little bit of tinkering for RStudio to accept the version of Python you want to use. I was using an Anaconda installation, and it was not immediately recognized.</p><p>The bigger issue is that while for the most part reticulate does a good job at converting objects, there are times where it does not work properly. For example, I found that date objects coming in as part of a pandas dataframe, do not convert nicely to an R dataframe.</p><p>The second con essentially defeats the purpose of using reticulate for this particular workflow. If the whole point is being able to seamlessly go back and forth between R and Python for cleaning and modeling, then all objects have to convert properly.</p><h3>Should you use it?</h3><p>Probably not. But you should <strong>TRY</strong> it!</p><p>The reason why I wanted to write this article is to make people aware that this is a possibility. While it may not be mature enough as of now to serve as a robust workflow, I do believe that some day it will be.</p><p>Regardless, I had a good time testing out this feature and I think everyone should give it a shot. It may not replace a Python IDE, but still nice to have the option to inject some Python code to be used in R if needed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91a78d74a0da" width="1" height="1" alt=""><hr><p><a href="https://medium.com/compassred-data-blog/r-vs-python-why-not-both-91a78d74a0da">R vs Python, why not both?</a> was originally published in <a href="https://medium.com/compassred-data-blog">CompassRed Data Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Market-Basket Thanksgiving]]></title>
            <link>https://medium.com/compassred-data-blog/a-market-basket-thanksgiving-c6ce0b22931e?source=rss-ae6de64c7449------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6ce0b22931e</guid>
            <category><![CDATA[marketing]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[market-basket-analysis]]></category>
            <category><![CDATA[recipe]]></category>
            <category><![CDATA[thanksgiving]]></category>
            <dc:creator><![CDATA[Eugene Olkhov]]></dc:creator>
            <pubDate>Thu, 14 Nov 2019 14:32:36 GMT</pubDate>
            <atom:updated>2019-11-15T14:44:35.071Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aQNc20M0Jsff9IlD" /><figcaption>Photo by <a href="https://unsplash.com/@element5digital?utm_source=medium&amp;utm_medium=referral">Element5 Digital</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Thanksgiving is almost upon us, and that means lots of cooking and looking up new recipes!</p><p>As someone who frequently visits food blogs, I sometimes get a bit overwhelmed from the sheer volume of recipes, and especially the number of ingredients that they require. A question that I started thinking about recently, is can I determine which ingredients are used in most recipes so that I can cook a variety of meals with as few ingredients as possible?</p><h3>Market-Basket Analysis</h3><p>One way we could answer that question is by conducting Market-Basket Analysis. This type of analysis is frequently used in marketing to develop associations between products that customers purchase. For example, one use case is grocery stores can determine which item is typically purchased with a group of other items and use that knowledge (called “rules”) to place certain items closer in proximity inside a store.</p><p>This technique can also be used to find ingredients that are associated with other recipes, which is what I aim to find out with this analysis.</p><p>While this is not intended to be a fully-fledged tutorial on conducting Market-Basket Analysis, there are some terms that are important to know in order to understand the results, which I very briefly cover below.</p><p><strong>Support</strong></p><p>The output of market-basket analysis is a set of rules:</p><pre>{Burger, Fries} =&gt; {Soda}</pre><p>The probability that all of the items appear together in the data is the support. If half of transactions (or recipes) contain burger, fries and soda, the support would be 0.5.</p><p><strong>Confidence</strong></p><p>The probability that someone will purchase Soda with Burger and Fries is the confidence. If Soda is always purchased with Burger and Fries, then the confidence is 1.</p><p><strong>Lift</strong></p><p>The lift is a little more tricky, but essentially it is a ratio that tells us if the rule is more likely to occur than chance. A lift ratio higher than 1 suggests that the rule/relationship does occur more frequently than chance, and the higher the number the more useful the rule is.</p><h3>Data</h3><p>The data for this analysis can be found on <a href="https://www.kaggle.com/kaggle/recipe-ingredients-dataset">Kaggle</a>, and it was donated by <a href="https://www.yummly.com/">Yummly.com</a>. It contains 39,774 recipes (in the training set, which is what I used), as well as labels for the cuisine the recipe is associated with. For this analysis, I decided to get rid of the cuisine labels and focus solely on the ingredient list.</p><p>To get a sense of the data, we can take a look at the most frequent items:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Onj4XwrI5Os3iYyLbQiLiw.png" /></figure><h3>Analysis</h3><p>This analysis was conducted using R and the arules package. This package implements the Apriori algorithm and makes conducting Market-Basket Analysis very easy.</p><p>After some work massaging the data into the shape that arules requires, I was able to get the first set of rules. In order for the package to return rules, there needs to be an input of the minimum support and minimum confidence. This is needed since with a large dataset, such as the one used here, building every possible rule will simply be overwhelming (and computationally expensive). To start, I used support = 0.005 and confidence = 0.8. The minimum support in this case required itemsets to appear in the data at least 105 times to be included in a rule. This resulted in only 64 rules being written. Here’s a sample of some of them when sorted by highest lift:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*b-yBluU0XwAm3AbZFwjtXw.png" /></figure><p>In hindsight, it should not be a huge surprise looking at these results. Ingredients such as flour and salt have very high support since they are included in so many recipes. The relatively high support also means that the ingredients on the left-hand side of the rules will also be common ingredients. So, all this is showing us are common ingredients that also are used with other common ingredients — butter, onions, pepper, salt, flour, etc.</p><p>What happens if we reduce the minimum support to allow for some less common ingredients?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*569GonjrAjJfQV-Z" /><figcaption>Photo by <a href="https://unsplash.com/@paolobendandi?utm_source=medium&amp;utm_medium=referral">Paolo Bendandi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>More spices!</p><p>We start to see a breakdown of common ingredients by type of cuisine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*YxRSNduo0ZSr4q2w2ZvjSg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*7B6i9I9NkW9WGUtKMS6KiA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*g7FgJG3iRijBv53Hsw9X5Q.png" /></figure><p>However, the rules still consist of spices, and common pantry staples such as flour, eggs, baking powder, etc.</p><p>While further analysis could look at taking out the most common ingredients and look at what rules are developed, the point still stands that if you are preparing to do a lot of cooking, prepare your pantry with many types of spices! In particular these are the spices you should definitely keep in your pantry based on this analysis:</p><ol><li>Onion powder</li><li>Cloves</li><li>Cumin seed</li><li>Ground turmeric</li><li>Garlic powder</li><li>Paprika</li><li>Sesame oil</li><li>Soy sauce</li><li>Ground cumin</li><li>And of course…salt and pepper!</li></ol><p>These can be used in many recipes, and can make a lot of people <em>thankful</em> during Thanksgiving.</p><p>Happy Cooking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6ce0b22931e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/compassred-data-blog/a-market-basket-thanksgiving-c6ce0b22931e">A Market-Basket Thanksgiving</a> was originally published in <a href="https://medium.com/compassred-data-blog">CompassRed Data Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is it Possible to Segment Breast Cancer Diagnoses Based on Image Characteristics?]]></title>
            <link>https://medium.com/compassred-data-blog/is-it-possible-to-segment-breast-cancer-diagnoses-based-on-image-characteristics-ccc7fae216d0?source=rss-ae6de64c7449------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccc7fae216d0</guid>
            <category><![CDATA[healthcare]]></category>
            <category><![CDATA[breast-cancer-awareness]]></category>
            <category><![CDATA[clustering]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[analytics]]></category>
            <dc:creator><![CDATA[Eugene Olkhov]]></dc:creator>
            <pubDate>Thu, 10 Oct 2019 15:35:21 GMT</pubDate>
            <atom:updated>2019-10-10T15:42:46.847Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*YBxcN9_WO0rF9LCI" /></figure><p>Since October is Breast Cancer Awareness Month, I wanted to do some type of analysis using a breast cancer dataset. There is a popular dataset available on Kaggle and the UCI Machine Learning Repository that contains diagnosis data which looked like a good contender for an interesting analysis.</p><p>The data used in the analysis were originally provided by the University of Wisconsin. They are numerical variables which were obtained based on digitized images of a fine needle aspirate of a breast mass and describe cell nuclei characteristics present in the image.</p><p>Each observation is a nucleus which is described by 30 features (10 original features — with 3 metrics for each: mean, standard error, and worst (average of largest 3):</p><p>1) radius (mean of distances from center to points on the perimeter)</p><p>2) texture (standard deviation of gray-scale values)</p><p>3) perimeter</p><p>4) area</p><p>5) smoothness (local variation in radius lengths)</p><p>6) compactness (perimeter² / area — 1.0)</p><p>7) concavity (severity of concave portions of the contour)</p><p>8) concave points (number of concave portions of the contour)</p><p>9) symmetry</p><p>10) fractal dimension (“coastline approximation” — 1)</p><p>Each observation has a label of M (Malignant) or B (Benign).</p><p>This is a popular dataset, and many analyses already exist that focus on using features to classify observations as benign or malignant. Given the plethora of similar analyses, I wanted to do something different. In this analysis, clustering (k-means) is used to create two clusters based on the 30 features in an attempt to naturally segment the data into a benign and malignant segment.</p><p><strong>Normalization</strong></p><p>The first step in the analysis is to normalize all features in order to put them on the same scale. Without doing this, the clustering algorithm will prioritize features due to a larger scale (e.g., perimeter and smoothness have completely different scales and perimeter will be treated as more important just due to the difference in scale).</p><p>There are many ways to normalize data, but my preference is “squeezing” each feature to a value between 0 and 1. This is done by subtracting the minimum value in a feature for each observation and dividing by the range of values of the feature (maximum — minimum). The downside of normalizing is it makes interpretation more difficult since the values being used are not on the original scale. We can save the minimum and maximum values so we can later transform the data back to its original scale. This is done by multiplying the normalized value by the range of the original values and then adding back the original minimum.</p><p><strong>Clustering</strong></p><p>Typically, the first step in clustering after preparing your data is to choose how many clusters is ideal to use. A scree/elbow plot is useful for this and shows you an ideal number of clusters solely from an error perspective. It’s a good start, but it needs to be paired with some knowledge of the problem. In our case, since there are only two outcomes (benign vs malignant), it does not make sense to use more than two clusters.</p><p>Before clustering, it’s important to remove the variable that lists the diagnosis of the observation. The goal is to see if we can segment the data by diagnosis using the characteristics of the nuclei, and we <em>do not</em> want the actual diagnoses to influence the results.</p><p>Running the clustering algorithm for two clusters results in the following breakdown of cluster sizes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*34AIx5_CPEIb7QpDa8uQ4A.png" /></figure><p>Roughly ~200 observations were bucketed in Cluster 1, while about ~400 were bucketed in Cluster 2. Next, we can look at our primary aim, and that is whether the clustering was able to segment diagnoses into benign and malignant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*f6-YYvrhaK3x6U0GhSlHng.png" /></figure><p>The above plot looks at the percent of observations in each cluster that have a malignant diagnosis. This shows that the clustering was able to segment the diagnoses without even seeing them very well. Cluster 1’s observations are ~95% malignant cases, while Cluster 2’s observations are only ~8% malignant cases.</p><p>This is impressive because we took out the diagnosis variable before clustering, so this is done solely with the other features.</p><p><strong>Important Features</strong></p><p>Finally, we can look at some of the important features by diving into the centers of the clusters. First, it would be useful to transform the features back into their original scale.</p><p>Overall, feature centers are much higher in Cluster 1, and lower in Cluster 2. Typically, the data shows that larger values are worse, and smaller values are better. This makes sense since cancer is more visible if it is larger. However, it would still be interesting to look at some of the highest feature centers for Cluster 1 and see what is more indicative of a malignant vs benign diagnosis.</p><p>The highest three centers in the first cluster are concave.points_worst, perimeter_mean, and radius_mean. Below are the values in their original scale for these three features for both clusters. This can let us compare the difference between the two.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*mhh2-KVcjX6odWnIuw7cLw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*2jU4LYXSQSbnFtPbYttj2A.png" /></figure><p>Here we can see the differences between the two clusters based on the largest three centers in the first cluster. On average, in the first cluster the largest concave points are more than double when compared to the second cluster, the perimeter is ~1.5 times larger, and the average mean radius in the first cluster is also quite a bit higher than in the second cluster.</p><p>This gives us an idea of what type of features matter when making a diagnosis, and while it seems obvious that larger nuclei are more likely malignant, it is still good to see it represented by the algorithm.</p><p>This analysis used clustering in a semi-supervised way. Typically, clustering is used solely for unsupervised learning where there are no given labels and the goal is to use features of data to cluster into segments. However, in this case, after performing the segmentation, the labels are brought into the analysis and used to see how well the data was segmented and the importance of features.</p><p>This type of approach has been successfully used at <a href="http://www.compassred.com/">CompassRed</a>, and it is a helpful technique which allows use of attributes not part of the clustering process to help label segments (as done here by labeling the first cluster as malignant and the second cluster as benign).</p><p>The healthcare space is becoming a popular field for data science, and there is a lot that can be done to improve people’s lives.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccc7fae216d0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/compassred-data-blog/is-it-possible-to-segment-breast-cancer-diagnoses-based-on-image-characteristics-ccc7fae216d0">Is it Possible to Segment Breast Cancer Diagnoses Based on Image Characteristics?</a> was originally published in <a href="https://medium.com/compassred-data-blog">CompassRed Data Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Current and Future State of Recommender Systems]]></title>
            <link>https://medium.com/compassred-data-blog/current-and-future-state-of-recommender-systems-ea3c4669c6ba?source=rss-ae6de64c7449------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea3c4669c6ba</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[recommender-systems]]></category>
            <category><![CDATA[matrix-factorization]]></category>
            <dc:creator><![CDATA[Eugene Olkhov]]></dc:creator>
            <pubDate>Tue, 10 Sep 2019 13:51:31 GMT</pubDate>
            <atom:updated>2019-09-10T14:14:10.662Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Xhzm-5ZQTN8aYS2B" /><figcaption>Photo by <a href="https://unsplash.com/@freestocks?utm_source=medium&amp;utm_medium=referral">freestocks.org</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this day and age, we have so many choices when it comes to making online purchases, watching a TV show or movie using a video streaming service, or finding songs to listen to online. Given the plethora of choices, companies need some way of curating content for customers, since browsing through millions of products on a website is just not feasible.</p><p>Enter recommender systems. If you have ever shopped on Amazon, or watched a TV show on Netflix, you have encountered recommender systems at work. Not only do recommender systems provide a way to quickly show customers what they are looking for, but they also help customers discover new products or media that they might like.</p><p>A well-built recommender system can lead to an excellent customer experience, which is why understanding how they work is highly important from a data science perspective. Recommender systems were simple in their early days, and have since evolved into more complex models.</p><h3>Overview of Recommendation Systems</h3><p>The common idea in different recommender systems is that there needs to be some measure of similarity.</p><p>The two most popular ways in which recommendations are done are:</p><ol><li>Item-based: Finding a similarity between items, and recommending an item based on interest of a similar item. For example, if I watch an episode of <em>Marvel’s</em> <em>Agents of Shield </em>on Netflix, I would see other Marvel-related content in my TV recommendations. This is also called “Content-based filtering”. A benefit of using this approach is that you do not have to rely on a lot of user data since the similarity calculation is happening at the item level.</li><li>Customer-based: Finding similarity between customers, and recommending an item that a similar customer has purchased/watched. This is also called “Collaborative filtering”. A benefit of this approach is that it works better for discovery, since items that look unrelated initially, might be liked by similar customers. Again taking the Netflix example, if I watch an episode of <em>Marvel’s</em> <em>Agents of Shield</em>, and other people who have watched <em>Marvel’s Agents of Shield </em>also watch <em>The Office</em>, then I would get a recommendation for <em>The Office,</em> even though the two shows seemingly have little in common.</li></ol><p>Recommender systems could also combine these two methods into a hybrid approach which can benefit from the strengths of both item-based and customer-based methods.</p><h3>Current State</h3><p>While in the beginning of recommender systems it was important to find explicit similarity in people and products, a more effective method has been used to look at similarity of latent attributes. This is done by using matrix factorization. To oversimplify, all of the attributes for an item or a customer are combined in a way which reveals relationships that have not yet been realized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aVBt1fQTdmyCavCW" /><figcaption>Photo by <a href="https://unsplash.com/@thkelley?utm_source=medium&amp;utm_medium=referral">Thomas Kelley</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Math has a way of looking like magic at times.</p><p>A simple example of this is using matrix factorization to determine movie genres, without actually inputting what the genres are. While this seems pointless since all movies already have a predefined genre, this technique can allow new genres to be determined which fit the viewer-base in a way that results in better recommendations.</p><p>The algorithm can look at attributes such as title, names of actors in the movie, name of director, movie run-time, and many other attributes and output a new “genre” such as “appealing to the 25–35 age range”. It is worth noting that the algorithm will not give a name for a new genre, but will still incorporate it into the recommendation.</p><h3>Future State — Deep Learning</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EzmsbTt0LiwS3VMijo9Qgg.png" /><figcaption><a href="https://www.youtube.com/watch?v=P06gZ4jwPls">Source: Amazon re:MARS</a></figcaption></figure><p>Neural Networks and Deep Learning have been all the rage the last couple of years in many different fields, and it appears that they are also helpful for solving recommendation system problems.</p><p>Ben Allison, a Principal Machine Learning Scientist at Amazon, <a href="https://www.youtube.com/watch?v=P06gZ4jwPls">gave a great talk</a> earlier this year at Amazon’s re:MARS conference about building recommender systems using Recurrent Neural Networks and Deep Learning.</p><p>One of the benefits of Deep Learning is similar to matrix factorization, in that there is an ability to derive latent attributes. Deep Learning, however, can make up for some of the weaknesses of matrix factorization such as the inability to include time in the model — which standard matrix factorization isn’t designed for. Deep Learning, however, can utilize Recurrent Neural Networks which are specifically designed for time and sequence data.</p><p>Incorporating time into a recommender system is important, because there are often preference seasonal effects. For example, it is likely that in December, more people are going to be watching holiday-themed movies and buying home decorations.</p><p>Another point that Ben Allison brought up is the need to see what would happen if a customer was shown a sub-optimal recommendation. This is taking a reinforcement learning approach, since the goal in this case would be to show customers a recommendation, and then record what the customer does. At times, customers can be recommended something that does not seem like the best option, just to see how the customer reacts which will improve the learning in the long-term.</p><p>Recommender systems can be a very powerful tool in a company’s arsenal, and future developments are going to increase business value even further. Some of the applications include being able to anticipate seasonal purchases based on recommendations, determine important purchases, and give better recommendations to customers which can increase retention and brand loyalty.</p><p>Most businesses will have some use for recommender systems, and I encourage everyone to learn more about this fascinating area.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea3c4669c6ba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/compassred-data-blog/current-and-future-state-of-recommender-systems-ea3c4669c6ba">Current and Future State of Recommender Systems</a> was originally published in <a href="https://medium.com/compassred-data-blog">CompassRed Data Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>