<?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 Gal Gilor on Medium]]></title>
        <description><![CDATA[Stories by Gal Gilor on Medium]]></description>
        <link>https://medium.com/@gal-gilor?source=rss-9a2fa2a33f07------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*2ZqID94N-K0yGcBDGW-HUw.jpeg</url>
            <title>Stories by Gal Gilor on Medium</title>
            <link>https://medium.com/@gal-gilor?source=rss-9a2fa2a33f07------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 05:52:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gal-gilor/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[Fluff Lichtenfurr — How to Create Modern Art in Python]]></title>
            <link>https://gal-gilor.medium.com/fluff-lichtenfurr-how-to-create-modern-art-in-python-d801e7d1897b?source=rss-9a2fa2a33f07------2</link>
            <guid isPermaLink="false">https://medium.com/p/d801e7d1897b</guid>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[scikit-image]]></category>
            <dc:creator><![CDATA[Gal Gilor]]></dc:creator>
            <pubDate>Fri, 13 Nov 2020 16:36:41 GMT</pubDate>
            <atom:updated>2020-11-13T16:41:13.737Z</atom:updated>
            <content:encoded><![CDATA[<h3>Fluff Lichtenfurr — How to Create Modern Art in Python</h3><h4>Image Manipulation with Scikit-Images</h4><p>After moving into a new apartment, my wife and I wanted to fill the spaces on our empty white walls. You may not know my wife and me, but naturally, we agreed on having more of our dogs on the wall. We had two 12&quot; by 16&quot; sized frames lying around, and my wife proposed we print out pictures of our beloved companions. In our defense, they are incredibly cute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8VJj3kaPNoGkpGI9TWrDeQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lB3vtwVBTF-qIvOhft_7EQ.jpeg" /><figcaption>On the left, the beautiful Lilo. On the right, the furrylicious Tooshi</figcaption></figure><p>Even though both of them are incredibly photogenic, I suggested to make this project more interesting and to apply the images with different filters. Also, the photos we picked were taken by an older phone camera, and enlarging the photos too much would make them look pixelated.</p><p>At first, I thought which tools would be best suited for this task. I decided I want this task to be simple and that, at the moment, I did not need to use the robust image processing APIs OpenCV and Pillow in this project. For this project, I used scikit-images (skymage) with different Matplotlib colormaps.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d25251e9f6f9b9eca29eaccb0d95c6b2/href">https://medium.com/media/d25251e9f6f9b9eca29eaccb0d95c6b2/href</a></iframe><p>If you include the reverse colormaps, Matplotlib has over 130 colormaps to choose from. I limited my options by only testing the Perceptually Uniform Sequential and Sequential colormaps. I created a function that accepts the images I want to hang on the wall, the figure size, and a colormap to test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28a34d3f6983f65cfb2835bb2affd1dc/href">https://medium.com/media/28a34d3f6983f65cfb2835bb2affd1dc/href</a></iframe><p>I ran this function with my dogs&#39; photos and tested every one of the 32 different colormaps. Do note; I chose to display the images as they get created. To reduce runtime, or if you lack internal memory to hold many figures at once, there are workarounds. Out of those 32, I managed to narrow the options to 3 colormaps that my wife and I agreed looked best.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*YTfE0L0pcOhp1ZenRnjq6Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*af7Dx-xykE_KWzoxKQBCNQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*-H0oW0qNcK_8Kxe8IAZMsA.png" /><figcaption>From left to right, gist_gray, gist_heat, and Viridis</figcaption></figure><p>Seeing the images alongside side one another sparked a different idea. Instead of stretching one image to fit the frame, I could fit the same image with different filters several times, fixing the pixelation problem once we print it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d823ede7997a1ff1b1d16e11371fe0d7/href">https://medium.com/media/d823ede7997a1ff1b1d16e11371fe0d7/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*2uCO16cS01JNkrufTNj6pA.png" /><figcaption>From left to right, gist_gray, gist_heat, and Viridis</figcaption></figure><p>Even though it’s clear I’m no Andy Warhol, and although this wasn’t the outcome exactly what my wife wanted, I believe I made a step in the right direction. In another attempt to create a magnificent work of art, I created another figure containing the same 4 images. This time, the images are in gray, red, green, and blue colorspaces. Not surprisingly, they are still gorgeous.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b8347b9d6029c642646a56dfd92cd76/href">https://medium.com/media/5b8347b9d6029c642646a56dfd92cd76/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*CzFJ-b32rgEADUgtI8ZwLw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*IGqkB_CpMa8_GH3BHKvhIw.png" /></figure><p>I have barely begun scratching the surface in the realm of possibilities. For example, creating my own colormaps or creating filters to change the images even further (e.g., creating my own Roy Lichtenstein style images). Before I feel comfortable printing those, I want to adjust the figure, so each plot is similarly spaced from the other plots. Feel free to leave a comment on the best ways to manually control the figure since I know tight_layout() is working against me in this case.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d801e7d1897b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Last Explanation You Will Ever Need to Answer This Conditional Probability Question]]></title>
            <link>https://medium.com/analytics-vidhya/the-last-explanation-you-will-ever-need-to-answer-this-conditional-probability-question-f39f8e93086c?source=rss-9a2fa2a33f07------2</link>
            <guid isPermaLink="false">https://medium.com/p/f39f8e93086c</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[genetics]]></category>
            <category><![CDATA[conditional-probability]]></category>
            <dc:creator><![CDATA[Gal Gilor]]></dc:creator>
            <pubDate>Thu, 05 Mar 2020 15:59:29 GMT</pubDate>
            <atom:updated>2020-03-06T12:22:42.740Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>Question: A couple has two children, what is the probability that both children are girls given that one of the children is a girl?</strong></blockquote><p>Hint, the answer is not 50%. In this article, I will frame this question from a different perspective. I will begin by supplying a short introduction to the human genetic code and how it’s stored. Then, I’ll answer the question with and without using the conditional probability formula.</p><p>Each cell in our body contains a big recipe book that holds the recipes to almost every protein the body needs to survive (and more). We call this recipe book the genetic code, and in humans, it’s made of DNA molecules. This book is comprised of components called chromosomes. There are 46 chromosomes, 23 pairs. Twenty-two of those pairs are called autosomes and are similar between males and females, while the 23rd pair is called the sex chromosomes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*a5SSMEZpjS0fy0-o.jpg" /><figcaption>Fig. 1 — Karyotype, Human chromosomes lined up in pairs and numbered by size. Source: <a href="https://ghr.nlm.nih.gov/primer/basics/howmanychromosomes">U.S National Library of Medicine</a>.</figcaption></figure><p>The first 22 pairs are numbered according to their size. The sex chromosomes are significantly different from each other in size and received unique names (Fig. 1). Typically, each person gets one random copy of every chromosome from each parent, although natural mutations can happen. Females are usually represented as having two ‘X’ chromosomes, and males with one ‘X’ and one ‘Y’ chromosomes as their 23rd pair. In summary, the female sex chromosome pair is made up of 2 different ‘X’ chromosomes that they received from their parents. The male sex chromosome pair is made up of the ‘X’ chromosome from the mother and the ‘Y’ chromosome from the father (Fig 2).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*MN7ZD63cSypnK3MhvkFkkQ.png" /><figcaption>Fig. 2 — Segregation of human sex chromosomes. The blue background represents the female offsprings, and the yellow background represents the male offsprings.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/0*KzYXhrGZdTcshD_u.gif" /><figcaption>Fig. 3 — Conditional Probability Formula. Source: <a href="http://www.stat.yale.edu/Courses/1997-98/101/condprob.htm">Yale University</a>.</figcaption></figure><p>Conditional probability is the probability of an event happening given that another event has occurred, assuming the events are not independent of each other (Fig. 3). In this question, we are assuming the sex of the children is already decided, the parents know the sex of their children (<a href="https://en.wikipedia.org/wiki/Boy_or_Girl_paradox#Second_question">Boy Girl Paradox</a>), and the events in the question are dependent on each other.</p><h4>Reminder</h4><blockquote>Q: A couple has two children, what is the probability that both children are girls given that one of the children is a girl?</blockquote><h4>Solution — Using Conditional Probability Formula</h4><p>Translating it to our situation, the probability of having two girls given that one of the children is a girl equals to the probability of having two girls, divided by the probability of having at least one girl (Fig. 4). The sample space, S = {(G,G), (G,B), (B,G), (B,B)}, where G is a girl, and B is a boy in the tuples. The intersection between the events of having two girls and at least one girl is, of course, having two girls — P(A ∩B) = {(G, G)}. And, the event of having at least one girl — P(B) = {(G,G), (G,B), (B,G)}.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*-lfkGjD-Bm3CVYAPQ-xzwQ.png" /><figcaption>Fig. 4 — Conditional Probability Formula. Event A, the parents have two girls. Event B, the parents have at least one girl.</figcaption></figure><h4>Tree Diagrams</h4><p>Tree diagrams are a great way to help visualize this kind of problem since they help plot the entire event space. Each branch in the tree represents a possible outcome in our event space. More often, tree diagrams are used in simple situations such as this one since they get complicated quickly. For this question, I created a four branches tree diagram (Fig. 5). Each rectangle in Fig. 5 displays an event (girl or boy), and the probability of that event happening (typically, it’s the same probability of having a girl and a boy).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gUjB8pHGsFe2O9MuzlFY6A.png" /><figcaption>Fig. 5–Tree diagram describing the event space.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*HJVW9haBwCvmzKUTYtlXUg.png" /><figcaption>Fig. 6 — Calculating the probability of both children being girls, given that the parents already have one girl using the tree diagram in Fig. 5.</figcaption></figure><p>So, referring back to the conditional probability formula and the events that make up the solution (Fig. 4). Event A and B, the event of having two girls {(G, G)}, is represented by the right branch of the tree, having a girl and then having another girl (1/2 x 1/2, Fig. 5). Event B, the events where the parents have at least one girl, is the cumulative outcome of the three right branches {(G, G), (G, B), (B, G)}. If the first child is a girl, the sex of the second child doesn’t matter. So, both the two right branches (1/2 x 1/2, two times, Fig. 5) are part of the event. Additionally, if the first child is a boy, the only other option is for the second child to be a girl (1/2 x 1/2, Fig. 5). Now, when we divide these outcomes, we get the same result, 1/3 (Fig. 6).</p><p>I find the typical solution of simply plugging the numbers into the conditional probability formula less intuitive. Hopefully, the next solution will help you better understand why the answer is not 50%.</p><h4>Solution — Different Perspective</h4><p>There are four possible offspring concerning sex chromosomes; two girls and two boys (Fig. 2). Since we already know the parents have one girl (e.g., the blue rectangle, Fig. 6). We now have to find the probability of having another girl from the remaining three possible kids. Two boys and one girl (two yellow rectangles and one green rectangle, Fig. 6). So, the probability of having another girl given the fact the parents already had a girl, is the probability of picking a girl (e.g., the green boxes, Fig. 6) from the remaining three possible children (green and yellow boxes, Fig 6) — 1/3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*TLqm4fB2uE0t9LCm6LqEKg.png" /><figcaption>Fig. 6 — Segregation of human sex chromosomes. The blue box represents the female offspring that we already know of. The yellow boxes represent the male offsprings, and the green represents the remaining female in our sample space.</figcaption></figure><p>In summary, probabilities are expressions that we give based on past information, and new information can change those. The most important part of answering this question correctly lies in identifying that we got a piece of information that changed the initial probabilities. When solving for probability questions, you should look for the word “given.” The new information supplied by a “given” event usually means that you’re dealing with conditional probability questions and that initial probabilities have changed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f39f8e93086c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/the-last-explanation-you-will-ever-need-to-answer-this-conditional-probability-question-f39f8e93086c">The Last Explanation You Will Ever Need to Answer This Conditional Probability Question</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction to Deep Learning (Part 2)]]></title>
            <link>https://medium.com/better-programming/introduction-to-deep-learning-part-ii-f37f2794715a?source=rss-9a2fa2a33f07------2</link>
            <guid isPermaLink="false">https://medium.com/p/f37f2794715a</guid>
            <category><![CDATA[image-classification]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Gal Gilor]]></dc:creator>
            <pubDate>Tue, 26 Nov 2019 01:51:11 GMT</pubDate>
            <atom:updated>2019-12-03T00:58:20.771Z</atom:updated>
            <content:encoded><![CDATA[<h4>Getting into image classification</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PJ6DC9yB3lizT0leQDt2IQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@crackedsenseless?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Dustin Humes</a> on <a href="https://unsplash.com/s/photos/dragonfly?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In this blog post, I‘m going to provide an example of one of the use cases for deep learning — image classification.</p><p>Before describing my image classification project, I’ll give some biological background and introduce convolutional neural networks (CNN). In the next post, I will provide a more in-depth explanation about the mathematical equations that operate behind the scenes.</p><p>In <a href="https://medium.com/@gilorgal2010/deep-learning-101-cf9f935f9b56"><em>introduction to deep learning (part 1)</em></a>, I explained how deep learning (DL) is a subset of machine learning (ML) and that ML is a subset of artificial intelligence (AI).</p><p>Also, I described the history of neural networks (NN), what deep learning is, the basic building blocks (perceptrons), and the process that makes the algorithm stand out — backpropagation.</p><h3>Introduction</h3><p>In this project, I created a model that can distinguish between images of dragonflies and damselflies. Why did I choose to classify insects and not hotdogs?</p><p>Before becoming a data scientist, I studied biology and experimented with flying insects. One of the organisms that the lab I was working at experimented with was the blue-tailed damselfly (Ischnura elegans).</p><p>It was then that I learned that dragonflies and damselflies are very different from a biological standpoint, as different as dogs and cats.</p><h3>Taxonomy</h3><p>Taxonomy in a nutshell. The branch of science concerned with naming every living organism is called taxonomy. Taxonomists classify organisms based on similarities and their last common ancestor.</p><p>The last common ancestor of any set of organisms is the most recent individual which the organisms are described as directly descended from the individual.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*5YoNrFVg0zK0oSAF3_sXgA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*QQf4RSa-rf3g-McBNgk4eA.gif" /><figcaption>Fig. 1 — On the left, the scientific classification of a grizzly bear showing the different naming conventions for the different groups. On the right, the scientific classification of damselflies (Zygoptera). Source: <a href="http://bioweb.uwlax.edu/bio203/2010/bush_clai/index.htm">UW-LAX</a>.</figcaption></figure><p>As we go down the scientific classification ladder, the organisms share a more recent common ancestor, thus, sharing more features, and look more similar.</p><p>For example, despite the significant differences between Phyla’s, <em>Arthropods </em>(insects, spiders, etc.) and <em>Chordata </em>(mammals, fish, etc.) are part of the same kingdom<em>, Animalia (</em>animals)<em>. </em>Meaning they share a common ancestor and characteristic features.</p><p>Similarly, black and grizzly bears are also animals, and they share the features that are ubiquitous to all animals. However, they’re also part of the same genus, <em>Ursus</em>, meaning they<em> </em>share additional features that are unique to bears.</p><p>Dragonflies and damselflies are part of the order <em>Odonata</em>. The key features that differentiate between them are in the shape of their heads and wings.</p><p>In dragonflies, compound eyes take up the entire front side of the head while in damselflies, there’s a clear distinction between the eyes. Additionally, while not flying, damselflies fold their wings while dragons don’t.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*5bUZQuzHfXCFqaaJumMMuQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*E9CG4Y5jkISgDzxvfRXppQ.jpeg" /><figcaption>Fig.2 — Dragonfly (left), Damselfly (right). Source: <a href="https://sites.google.com/view/fgvc6/competitions?authuser=0">iNaturalist</a>.</figcaption></figure><h3>Convolution</h3><p>Generally, the computer processes an image as a tensor the size of the image height times the image width times the color channel, giving the pixel’s values between 0–255.</p><p>In image processing, convolution is the process of multiplying a smaller matrix, called kernel matrix, and part of the image the size of the kernel matrix and replacing the matrix’s central element with the sum of multiplication.</p><p>I could describe the kernel matrices as adjustable filters that perform different tasks, such as sharpen, blur, identify, etc. If you want to learn more, visit this page on <a href="https://en.wikipedia.org/wiki/Kernel_(image_processing)">Wikipedia</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/0*-BnGXshmWLCBmteL.JPG" /><figcaption>Fig. 3 — Image convolution using a three by three kernel matrix. Source: <a href="http://machinelearninguru.com/computer_vision/basics/convolution/image_convolution_1.html">MachineLearningGuru</a>.</figcaption></figure><h3>Pooling Layers</h3><p>Pooling layers are intermediate layers that help reduce the dimensionality.</p><p>Pooling layers pick the best values out of every convolution window, which helps prevent overfitting, and reduces the number of parameters while retaining important information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/0*DQE4Bs7TiVMtFIQg.jpg" /><figcaption>Fig. 4 — Pooling example. Source: <a href="https://deepai.org/machine-learning-glossary-and-terms/max-pooling">Deep AI</a>.</figcaption></figure><h3>Dropout Layers</h3><p>The dropout layer is a regularization technique used in NN. This layer randomly ignores neurons, preventing them from contributing to the activation of neurons downstream.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1YUueml4ERekFeFa.png" /><figcaption>Fig. 5 — Dropout example. Source: <a href="https://chrisalbon.com/deep_learning/keras/adding_dropout/">Chris Albon</a>.</figcaption></figure><h3>The Linnaeus Bot — Image Classification</h3><p>Goal: Create a deep learning neural network that can accurately classify whether an image contains a dragonfly or a damselfly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*4e4nqeX0dYNNNcbmAUxWEg.png" /><figcaption>Fig. 6 Pie chart describing the number of images per animal.</figcaption></figure><p>The original dataset contained 8462 and 9197 color images of damselflies and dragonflies, respectively. The image size varied with max. dimensions of 800 pixels, weighing a total of 3.48 GB.</p><p>Having to overcome the constraints of working on my local machine, I processed the images by resizing them to 256 by 256 pixels, grayscale, normalized the pixel values (divide by 255), and augmented the image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*Bwtqn1f2vfPFSNaY8k0Gnw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*FqyLzfTAnpznzw_dpJcptw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*hpP3i6e47ZAPJueqRR_mUw.png" /><figcaption>Fig. 7 — Augmented dragonfly images. From left to right — resizing, grayscaling, and mirroring.</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/892fb66fc6805b0cb207779aeab997b1/href">https://medium.com/media/892fb66fc6805b0cb207779aeab997b1/href</a></iframe><h3>Creating the Training and Testing Sets</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*-zQu0cylqkPBQCPi4JuxEQ.png" /><figcaption>Fig. 9 — Total number of damselfly (damsels) and dragonfly (dragons) images.</figcaption></figure><p>After processing, I had a total of 35318 images (452 MB): 16924 damselfly and 18394 dragonfly images.</p><p>The training set consists of 12694 damselfly and 13797 dragonfly images, and the test set includes the remaining 8827‬ images. Also, 5% of the training images were used to validate throughout the training process.</p><p>In the end, I saved the data in four <a href="https://numpy.org/">NumPy</a> files; damselfly training set, damselfly testing set, dragonfly training set, and dragonfly testing set.</p><h3>Training the Model</h3><p>Despite computational limitations, I tried to follow <a href="https://neurohive.io/en/popular-networks/vgg16/">VGG16</a>’s basic CNN structure, two convolution layers followed by a pooling layer.</p><p>Additionally, I added a dropout layer after every basic CNN structure to reduce overfitting. Furthermore, after the convolutional layers, I added two 128 neuron dense layers and additional dropout layers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdd22e9361c03d8a98b9ea64dac08741/href">https://medium.com/media/cdd22e9361c03d8a98b9ea64dac08741/href</a></iframe><p>Since I was unable to allocate memory for all 26491 images, I trained the CNN in batches of 4000 images at a time. Each batch of images consists of 2000 damselflies and dragonflies photos, where 5% were used for validation purposes.</p><p>I repeated the process of training the model on a set of images for ten epochs, saving the model weights, clearing the cache, and loading a new collection of images six times (24000 photos total).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*04lfbUl6fUwlXZDeWaitrw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*NNgKpUaYCce25DQhavJAsA.png" /><figcaption>Fig 11 — Changes in accuracy and loss during model training on the training and validation sets.</figcaption></figure><h3>Results</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*NRYH-yy0ZgjO_8A4YETB5Q.png" /><figcaption>Fig. 12 — Confusion matrix showing the testing results.</figcaption></figure><p>After training the model on 24000 images, the model testing accuracy increased to 85.7% (35.7% better than a random guess for a binary decision).</p><p>Given the fact image quality varied, I’m content with this result. Some images in the dataset were blurry, not focused on the animal, or contained more than one animal, which effected the training process.</p><p>Still, overall, the model learned to generalize well. On the right side of figure 13, a photo containing mating dragonflies that the model misclassified as a damselfly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*7_abk-geGxYCwOLg2WNxjA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*RPlXzzp8GlA_PRty-o5gjg.png" /><figcaption>Fig. 13 — From left to right, correctly classified dragonfly and misclassified dragonfly.</figcaption></figure><h4>What the Model Sees</h4><p>Curious as to what the model sees in every convolution, I created an additional model to return a neuron activation map.</p><p>The next four images represent what the first four convolutional layers see. As expected, the network focuses more on the animal and less on the background in the more in-depth activation layers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hCvVfqu8Ohm_tLUMfnemrQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5XdeLw_8AnWqJIh3pLbgkw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xzjs6LFB0ec7tjNpYgKfUQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*juIY9wHYU259kREmBotngQ.jpeg" /></figure><h3>Summary</h3><p>In conclusion, despite the time constraints, this was a successful experiment, and eventually, I would like to train a model to distinguish between different species of dragon/damselflies.</p><p>However, several changes need to be implemented. I challenged myself to hardcode the image augmentation function, and to begin training the image classification model from scratch.</p><p>The next steps include introducing transfer learning to predict classes more accurately and to use <a href="http://keras.io/preprocessing/image/">Keras</a>’ ImageDataGenerator class to augment the data. For the full code, this project is publicly available on <a href="https://github.com/Gal-Gilor/The_Linnaeus_Bot">GitHub</a>.</p><h3>Extra Sources</h3><ul><li><a href="https://keras.io/">Keras: Deep Learning for humans</a></li><li><a href="https://machinelearningmastery.com/dropout-regularization-deep-learning-models-keras/">Dropout Regularization in Deep Learning Models With Keras</a></li><li><a href="https://www.mathworks.com/">MathWorks - Makers of MATLAB and Simulink</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f37f2794715a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/introduction-to-deep-learning-part-ii-f37f2794715a">An Introduction to Deep Learning (Part 2)</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multiple Linear Regression Experiment]]></title>
            <link>https://gal-gilor.medium.com/multiple-linear-regression-experiment-7ce3d6d30b87?source=rss-9a2fa2a33f07------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ce3d6d30b87</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[review]]></category>
            <dc:creator><![CDATA[Gal Gilor]]></dc:creator>
            <pubDate>Wed, 11 Sep 2019 21:13:31 GMT</pubDate>
            <atom:updated>2019-09-29T00:59:46.142Z</atom:updated>
            <content:encoded><![CDATA[<h3>Predicting the Life Expectancy of a Different Countries — Multiple Linear Regression</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*xIMfA1OBEcXVxBbhKxXGxw.png" /><figcaption>This image was taken from <a href="https://retireenews.org/2018/01/28/life-expectancy-is-down-for-a-second-year-drug-overdoses-are-a-big-reason-why/">retireneenew.org</a></figcaption></figure><h3>Introduction</h3><p>As part of my <a href="https://flatironschool.com/">Flatiron</a> experience, I was paired up with a <a href="https://www.linkedin.com/in/haider-hussain-mph-0050307b/">partner</a> and tasked to perform multiple linear regression, interpret the results and present the findings. In this blog, I am going to present, and criticize the steps we’ve taken along the way to complete the project. We divided the work into 5 steps:</p><ol><li>Find a suitable dataset</li><li>Perform EDA</li><li>Create a multiple regression model</li><li>Test the model</li><li>Interpret the results</li></ol><p>The dataset we picked was collected by the World Health Organization (WHO) and the United Nations by Deeksha Russell and Duan Wang. In this project, we performed multiple linear regression to find the key features to affect life expectancy in different countries. The overhead goal for this project was to find <em>which public health factors have the most significant impact on life expectancy in different countries</em>.</p><h4>Technical Description</h4><p>The dataset contains 2939 observations about life expectancy in different countries between the years 2000 and 2015. To clean and explore the data we utilized the <a href="https://pandas.pydata.org/pandas-docs/stable/index.html/">Pandas</a> library. For the data analysis, we used the <a href="https://www.numpy.org/">Numpy</a>, <a href="https://www.numpy.org/">Scipy</a>, and <a href="https://scikit-learn.org/stable/">Sklearn</a> libraries, and for graphing we used <a href="https://matplotlib.org/">Matplotlib</a>. To increase collaboration efficiency we created a <a href="https://github.com/DaggerForce/Life_Expectancy_Project/">GitHub</a> repository; this allowed us to work uninterrupted, simultaneously, and independently. The majority of our code was written in Jupyter Notebooks using Python. Additionally, we used <a href="https://code.visualstudio.com/">VSCode</a> to create a module that contains helper functions.</p><h3>Exploratory Data Analysis (EDA)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/0*lFWeD0pv7bNE4mU9.png" /><figcaption>Fig. 1. Correlation heat map</figcaption></figure><p>We began by creating new features, adjusting the column names, grabbing specific columns, and removing fragmented observations by dropping all the rows that were missing data. We then checked for possible relationships between the different features and looked at their kernel density plots. We then proceeded by searching for multicollinearity between the predictors by creating a correlation matrix and a heat map (fig. 1), omitting predictors that exceeded the cut-off we defined.</p><blockquote>Looking back, I would remove the fragmented observations only <strong>after</strong> picking the features. Even though enough data remained to create a model (1649 observations), we disregarded close to half the data. Additionally, while creating the new features and adjusting the column names we disregarded features <strong>we suspected were not significant.</strong> This is really not recommended, as a data scientist I should strive to eliminate bias as much as possible. Also, we should have separated our engineered categorical variable population size into different columns (create dummy variables).</blockquote><p>After picking the features we chose to include, we proceeded to remove possible outliers by looking at their scatter plots and removing the observations we deemed as unusual. Additionally, we transformed the data to meet the linearity assumption when needed. Also, we checked all the features’ distribution and transformed the data to achieve a more normal distributed data (fig. 2).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*_zJCk0YG28UcIhXl_TGuGg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*6nMmmiU1dkGoiS3oZM6sTg.png" /><figcaption>Fig. 2. Two histograms showing the distribution of observations before log transformation (left graph), and after (right graph)</figcaption></figure><blockquote>Although not perfect, we’ve done a decent job preparing the features to perform a multiple linear regression. We improved the linear relationship between the Dependant and independent variables, and made sure there’s little multicollinearity between our predictors. However, <strong>we didn’t remove the outliers from the dependent variable (life expectancy). </strong>Although linear regression models <strong>don’t make assumptions</strong> <strong>about the distribution of the dependent variables</strong>, we should have tried to adjust the skews in the life expectancy’s distribution<strong>. </strong>Additionally, If we had more time, we would added more features to model to differentiate between countries that are in war or suffering from a drought etc...</blockquote><h3>Modeling</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*q5GDeo1jA5K2tkEY3T66Cw.png" /><figcaption>Fig. 3. Model summary</figcaption></figure><p>After we adjusted the data to make ensure we meet the linear regression assumptions we scaled the variables and ran the model (fig 3). The model included the prevalence of HIV, prevalence of malnutrition, mortality ratio, lifestyle, education, infant mortality rate, and economy, and then looked at the distribution of residuals for homoscedasticity (fig. 4). To test the model, we performed a train, test, split test using 80% of the data to predict the remaining 20%. With an R squared of 0.804, our model explains 80%~ of variation in life expectancy in different countries. Unfortunately, the residuals were not homoscedastic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*cGrDTedhCBpJfQDa.png" /><figcaption>Fig. 4. The residual error histogram (left) and residual error scatter plot (right).</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*sAdTtMRv8JHy1iLZ.png" /><figcaption>Fig. 5. The model’s prediction versus the actual life expectancy. MSE = 3.022</figcaption></figure><p>Additionally, we created a model with all the features we previously excluded (BMI, alcohol, GDP, and population size) and performed a train, test, split again. Expectedly, the absolute mean error was slightly smaller (2.995).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*2Fu2SPpChXfV49ip.png" /><figcaption>Fig. 5 The inclusive of all predictors model predictions versus the actual life expectancy. MSE = 2.995</figcaption></figure><h3>Take-Home Message</h3><p>Our suggestions for countries looking to increase their life expectancy is to focus their resources mainly on increasing HIV awareness. Additionally, we recommend promoting education.</p><blockquote>Scaling the data before running the model is certainly a practice that should be reinforced especially since machine learning algorithms require the data to be scaled beforehand. Additionally, performing a train, test split is very important to prevent overfitting the model to the data. However, the assumption of homoscedasticity was not met. If we look at figure 4, the residual errors shows a trend of under predicting and over predicting the edge cases. Heteroscedasticity occurs more often in datasets that have a large range between the largest and smallest observed values. Linear regression is sensitive to outliers, one possible reason for the heteroscedasticity of residuals could be the fact that we have not removed outliers in life expectancy. Another possible reason is the fact that<strong> not all the independent variables showed a linear relationship with life expectancy</strong>. Despite the fact we tried several transformations, we could not fully meet this assumption and should have considered not using those features. Also, since we dropped columns before checking their correlation with life expectancy, our model could be inaccurate and missing features to explain those edge cases.</blockquote><h3>Summary</h3><p>At the end of the day, I wasn’t displeased with the work we’ve done given the time constraint. I enjoyed the learning process and working with my partner. Because it’s not perfect, I was able to learn from it and will know what to do or not to do next time I perform linear regression. If you have any questions feel free to message me, also, all the code used in this project is accessible on my Github <a href="https://github.com/DaggerForce/Life_Expectancy_Project">repository</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ce3d6d30b87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Deep Learning (Part 1)]]></title>
            <link>https://medium.com/better-programming/deep-learning-101-cf9f935f9b56?source=rss-9a2fa2a33f07------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf9f935f9b56</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Gal Gilor]]></dc:creator>
            <pubDate>Wed, 04 Sep 2019 15:19:41 GMT</pubDate>
            <atom:updated>2019-12-03T17:53:52.271Z</atom:updated>
            <content:encoded><![CDATA[<h4>How does deep learning relate to machine learning?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*zw71uPcy4PLnxAZ0k-CKgQ.png" /><figcaption>Photo by <a href="https://unsplash.com/@franckinjapan?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Franck V.</a> on <a href="https://unsplash.com/s/photos/artificial-intelligence?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In this article, I’ll try to explain what deep learning is and how it relates to machine learning.</p><p>Even though there’s a lot of sources discussing this subject online, I couldn’t point to one source that was both exhaustive and concise.</p><p>Before I begin explaining what deep learning is exactly, I’ll first explain a little about artificial intelligence, machine learning, neural networks, and the relationship between these topics.</p><p>This article is meant to provide you with a background on the topic while not going too in-depth. Hopefully, I’ll be able to release the second part soon, which will focus on the different types of neural networks and introduce the term <em>reinforcement learning.</em></p><h3>Artificial Intelligence</h3><p>Artificial intelligence (AI) is the scientific branch that emphasizes the development of creating machines that can operate similarly to humans. The machines are split into four main categories:</p><h4>Type 1</h4><p>This is the simplest type. It can decide without memory and the use of prior experience. This type of intelligence is reactive, meaning it can only react to a current situation. A good example of this type of AI would be IBM’s “Deep Blue” that was created to play chess.</p><h4>Type 2</h4><p>This type includes a limited memory and can derive knowledge from previously learned information to reach a decision — for example, Tesla’s self-driving cars and Netflix’s movie recommender. The cars can detect patterns in traffic and adjust as necessary without driver interference, and Netflix can recommend movies based on past movies you watched.</p><h4>Type 3</h4><p>This type can imitate the human state of mind, including their intentions. This kind of machine potentially would be able to identify, understand, retain, and remember emotional outputs while knowing how to respond to them.</p><p>One example is Kismet, developed by professor Cynthia Breazeal. Kismet is capable of showing facial expressions (emote how it feels) in response to what’s happening around it. Even though it isn’t able to hold a conversation, it has some aspects of emotive ability akin to that of humans.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*mds3hEp9kEeNH5x8HPWOyQ.png" /><figcaption>Fig. 1: Kismet emoting fear</figcaption></figure><h4>Type 4</h4><p>A self-aware AI, this type of machine posseses a human-level consciousness. Self-awareness would include the ability to recognize oneself as an individual. Additionally, this AI would be able to understand the concept of having feelings and desires. This type is still beyond human capabilities, and there are no self-aware machines.</p><h3>Machine Learning</h3><p>Machine learning is the main tool to analyze, understand, and identify patterns in data. It’s a subset of artificial intelligence that involves creating algorithms based on prior data to reach predictions without human interference.</p><p>The most notable algorithm concerning deep learning is the artificial neural networks (ANN) algorithm. ANNs are modeled loosely on biological networks and the way the human brain processes data.</p><p>Similar to biological neurons, perceptrons (artificial neurons) produce an output once a certain threshold is met. Each of those artificial neurons is associated with different weights and biases, which I’ll explain in detail later in the text. Figure 2 describes a simple ANN for a linear relationship, with an input and an output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*BalfPRc3D4UtwDTkd24JfA.png" /><figcaption>Fig. 2: Representation of a neural network without hidden layers</figcaption></figure><h3>Neural Networks</h3><p>Earlier in the text, I mentioned that artificial neural networks are constructed by perceptrons and that each perceptron has associated weights and biases.</p><p><em>Weights</em> are real numbers that express how important the received input is in order to help compute the output. For example, if the output is biking to work or not biking to work, the inputs could be the temperature and wind conditions. If I’m more sensitive to temperature changes, the decision of whether I bike to work will be more influenced by the temperature.</p><p><em>Bias</em> is an additional parameter that’s used to adjust the output along with the weighted sum of the inputs to the perceptron. Bias is an added constant that helps fit the model to the given data.</p><p>Together the weights and bias indicate the importance of the input in the decision-making process. If the weighted sum of all the inputs is greater than a predefined threshold, the output is 1. Otherwise, it’ll be 0.</p><p>To address a technical design flaw — very small changes in the input can flip the output and perceptrons will then behave like a step function — Frank Rosenblatt introduced the sigmoid perceptrons. The output from a sigmoid perceptron (neuron) is smoother than the step function and returns an S- shaped curve.</p><p>Using the sigmoid function, which is similar to the logistic regression function, the output of each neuron is a real value between 0–1, also known as the <em>activation function.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/0*9mCw_aLBlgKrH7FC.jpg" /><figcaption><a href="https://www.geospatialworld.net/blogs/difference-between-ai%EF%BB%BF-machine-learning-and-deep-learning/">Source</a></figcaption></figure><h3>Deep Learning</h3><p>According to <a href="https://www.geeksforgeeks.org/introduction-deep-learning/">GeeksforGeeks</a>:</p><blockquote>“Deep learning is a particular kind of machine learning that achieves great power and flexibility by learning to represent the world as a nested hierarchy of concepts, with each concept defined in relation to simpler concepts, and more abstract representations computed in terms of less abstract ones.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*uSf2-R5rOaWgLirxyBGNAg.jpeg" /><figcaption>Fig. 3: Multilayered neural network</figcaption></figure><p>Deep learning is a subset of machine learning where neural networks contain one or more hidden layers between the input and the output, each layer providing a different interpretation of the data it’s fed.</p><p>From this moment on, I’ll focus more on deep learning in feedforward neural networks. Feedforward neural networks are the first and simplest type of NN. They are named by the process of forward propagation. In forward propagation, each layer receives input and applies the different mathematical operations to produce an outcome.</p><p>To train an ANN, you must give it a measurement of how badly it performs. Usually, to measure its performance you create a cost function to estimate how badly the model performs — the higher the cost, the worse the model. Our goal is to minimize the cost as much as possible until we reach a minimum cost.</p><p>In deep learning neural networks, back-propagation and gradient descent enable the model to tweak itself and to reduce the cost function. Back-propagation applies the calculus chain rule recursively to adjust the weights and biases for every hidden layer before it. This process continues until the cost function reaches a minimum, the change in the cost is very small, or the machine reaches a predefined stopping point.</p><p>To sum it up, I’d describe deep learning as a way to describe algorithms that solve complex problems by breaking down the process into smaller pieces.</p><p>The main machine-learning algorithm that supports deep learning is NN because of their nested structure and their ability to process labeled and unlabeled data to create classifiers. For this reason, it’s currently believed that a NN or a variation of it is likely the algorithm that’ll allow us to replicate self-awareness in machines. However, this algorithm requires large amounts of data and computational power to function properly.</p><h3>References</h3><ul><li><a href="http://neuralnetworksanddeeplearning.com/chap1.html">Neural networks and deep learning</a></li><li><a href="https://towardsdatascience.com/why-deep-learning-is-needed-over-traditional-machine-learning-1b6a99177063">Why Deep Learning over Traditional Machine Learning?</a></li><li><a href="https://www.analyticsvidhya.com/blog/2017/04/comparison-between-deep-learning-machine-learning">Deep Learning vs. Machine Learning - the essential differences you need to know!</a></li><li><a href="https://medium.com/fintechexplained/neural-networks-activation-function-to-back-propagation-understanding-neural-networks-bdd036c3f29f">Understanding Neural Networks: From Activation Function To Back Propagation</a></li><li><a href="https://hackernoon.com/everything-you-need-to-know-about-neural-networks-8988c3ee4491">Everything you need to know about Neural Networks | HackerNoon</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf9f935f9b56" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/deep-learning-101-cf9f935f9b56">Introduction to Deep Learning (Part 1)</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Visualization Guide for Junior Data Scientists]]></title>
            <link>https://medium.com/analytics-vidhya/data-visualization-guide-for-junior-data-scientists-a384f78ab023?source=rss-9a2fa2a33f07------2</link>
            <guid isPermaLink="false">https://medium.com/p/a384f78ab023</guid>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[matplotlib]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Gal Gilor]]></dc:creator>
            <pubDate>Tue, 20 Aug 2019 00:54:02 GMT</pubDate>
            <atom:updated>2019-09-01T06:22:50.041Z</atom:updated>
            <content:encoded><![CDATA[<p>As a beginner data scientist, I often find myself staring at my results thinking about what would be the best way to present them. The most common methods to visually illustrate relationships in our data are graphs and tables. Graphs’ main purpose is to present data that is too complicated to describe in words. While tables are best used when you need to compare individual results or show precise values. The four basic presentation types for graphs are “comparison”, “composition”, “distribution” and “relationship”. In this post, I would like to teach you a little behind the intuition of choosing the right visualization tool, and how to make your charts more presentable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BENxf7fs-m0R-4Ztk5odNw.jpeg" /><figcaption>Basic presentation types chart and their associated graphs, created by <a href="https://extremepresentation.com/">Dr. Andrew Abela</a></figcaption></figure><p>There are many types of graph some more familiar than others. Before selecting a graph to present your data you need to know how many variables are you showing, how much data do you want to display, are your variables continuous or discrete? etc… You would most likely want to use the following charts when presenting your results. Even though there are many types of charts that may seem more exotic it’s important to keep it simple.</p><h4>Bar Graphs</h4><p>Bar graphs are most commonly used to compare a single variable value between several groups. When using bar charts to compare different categories avoid showing more than 7 categories and sort the columns by their height. If time is one of the dimensions it should always be set on the horizontal axis and run from left to right. Avoid using bar graphs to show composition unless there are no more than 2–3 variables. Additionally, consider using horizontal bar charts when your labels are long.</p><h4>Line Graphs</h4><p>Line graphs are used to track changes in <em>continuous</em> data over periods. They do best at visualizing bigger data sets with over 30 data points. Line graphs are usually designed with the dependent variable on the vertical axis and the independent variable on the horizontal axis. Similar to bar charts, if one of your axes is time, present the time from left to right. Furthermore, if you have missing data don’t skip over it and show a fragmented line. The aspect ratio, also known as the ratio between the width and the height plays a big part in how people perceive the results. Even though it’s true for other types of graphs using a reasonable aspect ratio is very important (most commonly used aspect ratio is 45 degrees).</p><h4>Scatter Plots</h4><p>Scatter plots are used to determine relationships between different variables. One axis is used to measure one event and the other axis is used to measure the other, to find a relationship between the variables. You could also use scatter plots to show the distribution or clustering trends within data. Additionally, it is a convenient way to find outliers. If your data doesn’t a show linear relationship, it’s considered a good practice to convert it into any different non-linear scale such as logarithmic scale. This helps you find a relationship in your data set that you were unable to find before.</p><h4>Pie Charts</h4><p>Pie charts are best to use when you are trying to compare parts of a whole. To show the composition of static data (doesn’t change over time). It’s recommended not to slice the pie into more than 5 pieces. You want to ensure you add the figures to strengthen the message you want to convey.</p><h4>Area Graphs</h4><p>Area graphs look similar to line graphs but they are used to track changes over time for a data sets comprised of multiple groups. Stacked area charts are great at showing changes in the composition of the data set over time. User discretion is advised when using area graphs. Avoid stacking more than 5 categories as the graph becomes cluttered quickly.</p><h4>Histograms</h4><p>Histograms are specialized types of bar graphs that represent data from measurement of <em>continuous </em>variables by grouping them into classes to show the frequency of the data in each class. The frequency is measured by the area of the column, and these graphs are typically used to check if a variable follows a normal distribution.</p><p>To ensure the graphs you produce are readable and professional, always title your axes, and add the unit measurement unit. On a side note, if one of your axes is in “Millions”, avoid using “m” as it denotes meters and “M” as it denotes thousand in roman numerals.</p><p>Avoid adding legends if they’re not needed. If a legend is needed choose a color deficiency friendly <a href="http://colorlab.wickline.org/colorblind/colorlab/">color schemes</a> to ensure the graph is comprehensible to color-blind people. 1 out of 12 men and 1 out of 200 women is color-blind, which estimates approximately 8.5% of the world’s population is color blind.</p><p>Always show the entire picture. Similar to how aspect ratio can skew with how people perceive results, in bar graphs having the dependent variable not beginning in zero could have a similar result.</p><p>Additionally, avoid mixing between chart types, and try using the more familiar charts to maximize readability.</p><h4>Examples</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*mpWo99c051hllVw3r5RonQ.png" /><figcaption>Fig 1. Basic Matplotlib bar chart</figcaption></figure><p><strong>Vertical column example</strong></p><p>To keep things simpler I will highlight some of the best practices examples using python’s Matplotlib library. Matplotlib creates very basic graphs overall. That’s not necessarily bad as simple is usually better (Fig. 1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*yePMoFEKKZKJUorIvepxAQ.png" /><figcaption>Fig 2. Basic bar chart with added titles</figcaption></figure><p>However, a person reading this graph can’t understand the story I’m trying to convey so I begin by adding titles and the unit measurements (Fig. 2).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*c-VsDbYwAyKkEuU1085RrA.png" /><figcaption>Fig. 3. Sorted data, highlighting a specific value, and removing some of the borders to give it a cleaner look.</figcaption></figure><p>Now that’s better, people viewing the graph can understand the context of the graph! In the next step, I’m going to guide them to results I want them to notice by sorting<em>*</em> the columns and add some colors to make it pop next to the other columns (Fig. 3).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*O-CBbka6eUIFxrofee9yvA.png" /><figcaption>Fig. 4. Basic bar graph with a 70-degree tilt to x-axis label</figcaption></figure><p><em>*You may have noticed that the sizes of the columns change. For the sake of simplicity, the categories were not assigned a specific value. Thus sorting the values did not sort the categories.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*9BH4uuPAePls4rGCfeAcWw.png" /><figcaption>Fig. 5. Sorted data, highlighting a specific value, horizontal bar graph</figcaption></figure><p><strong>Horizontal column example</strong></p><p>Even though it is possible to overcome unusually long label names by giving the x-axis labels a slight tilt (Fig. 4). However, when faced with this situation it is considered a better practice to switch axis between the categories we’re trying to compare and the values (Fig. 5).</p><h4>Summary</h4><p>In this post, I tried to give you a quick recap about how to choose the right graph, and most importantly some guidelines to ensure the visuals you create are concise and readable. The graphs are the products of your critical thinking and the audience must be able to comprehend the results. However, these guidelines are not set in stone, “to graph their own”. The data you’re working with won’t necessarily work well with all of the principles mentioned above. As long as the message is clear and concise, the message will be delivered.</p><h4>Some of the code used to create the examples</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2c614c0eebcc15dd68aba2f0868de0b/href">https://medium.com/media/a2c614c0eebcc15dd68aba2f0868de0b/href</a></iframe><h3>References</h3><ul><li><a href="https://uxdesign.cc/designing-charts-principles-every-designer-should-know-part-2-ce1e06af56fc">Designing Charts: principles every designer should know (part 2)</a></li><li><a href="https://eazybi.com/blog/data_visualization_and_chart_types/">Data Visualization - How to Pick the Right Chart Type?</a></li><li><a href="https://nces.ed.gov/nceskids/help/user_guide/graph/whentouse.asp">How Do I Choose Which Type of Graph to Use?-NCES Kids&#39; Zone</a></li><li><a href="https://whatis.techtarget.com/definition/bar-graph">What is bar graph? - Definition from WhatIs.com</a></li><li><a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4078179/">The Effective Use of Graphs</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a384f78ab023" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/data-visualization-guide-for-junior-data-scientists-a384f78ab023">Data Visualization Guide for Junior Data Scientists</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning in Biology — Bioinformatics]]></title>
            <link>https://gal-gilor.medium.com/machine-learning-in-biology-bioinformatics-fc71e9fe196f?source=rss-9a2fa2a33f07------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc71e9fe196f</guid>
            <category><![CDATA[biology]]></category>
            <category><![CDATA[bioinformatics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[intro]]></category>
            <dc:creator><![CDATA[Gal Gilor]]></dc:creator>
            <pubDate>Tue, 06 Aug 2019 21:54:21 GMT</pubDate>
            <atom:updated>2019-08-19T12:50:52.266Z</atom:updated>
            <content:encoded><![CDATA[<h3>Machine Learning in Biology — Bioinformatics</h3><blockquote>“Bioinformatics is the science of collecting and analyzing complex biological data”</blockquote><p>Bioinformatics combines elements of biology and computer science, using computational methods to analyze biological data. Since 1953 and the discovery of DNA the field of molecular biology has experienced a steep rise in the amounts of data to process. Scientists have been gathering large amounts of data of genome sequences from many species. Nowadays data analyses in bioinformatics predominately focus on large data sets such as macromolecular structures, genome sequences, etc…</p><h4>Predicting the three-dimensional structure of proteins by their building blocks</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*Pja8sa4pEyWr7bur4s6ETg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/228/1*w6XE3iTm-grdmWfFCZxK-g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*CNQLU3fyLt6zs2JbIysUuA.png" /><figcaption>This is a three-dimensional construction of a protein. Proteins have a structure-function relationship, understanding how the building blocks interact is important and complex.</figcaption></figure><h4>Comparing similar sequences between different species</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TlMrJshu-zWsRjx7bmVuNQ.png" /><figcaption>This is a snippet from a protein found in different species, it shows the similarities between the sequences</figcaption></figure><h4>Pathogenomics — Fighting Viral infections</h4><p>HIV develops immunity to drugs very fast and efficiently. Drugs used for treatment become obsolete incredibly fast, for that reason modern medicine conceived the “cocktail”. Mixing three or more different drugs that prevent the virus from spreading itself. However, for this to work we have to ensure the virus is not already resistant to one of the drugs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*GmXidPB2g80OZQk-oTEXJg.png" /><figcaption>This genome segment was taken from a strain of virus resistant to a certain drug.This genome segment was taken from a strain of virus not resistant to the same drug</figcaption></figure><p>if this seems simple, here are a few facts we have to remember. HIV genetic code is comprised of nine <a href="https://en.wikipedia.org/wiki/Gene">g</a>enes each one could be as long as 15000 bases (15kb). If you’re comparing human DNA samples, the human genome contains about 3 billion base pairs (3bps).</p><p>These are only a handful of examples showing why biologists needed to use computer science tools. Additionally, scientists around the world are constantly gathering genomic data from different organisms and upload their results to online databases such as <a href="https://blast.ncbi.nlm.nih.gov/Blast.cgi">BLAST</a> (Basic Local Alignment Search Tool) and <a href="http://geneontology.org/">GO</a> (Gene Ontology). However, people don’t always know what exactly the sample they uploaded is related to if it’s a gene or a regulatory sequence, etc…</p><h3>Types Of Learning</h3><h4>Supervised</h4><p>When you have prior knowledge about the data. Allows us to create predictions about new data (sample).</p><blockquote>The machine learning task of learning a function that maps an input to an output based on example input-output pairs. It infers a function from labeled training data consisting of a set of training examples.</blockquote><h4>Unsupervised</h4><p>Without prior knowledge about the data. Allows us to discover new classes. I will not go over unsupervised learning in this post.</p><blockquote>Type of machine learning algorithm used to draw inferences from data sets consisting of input data without labeled responses.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*lpHLTMYK-dH89diRTQ2uzA.png" /></figure><p>In this example, the red dots are “labeled” as samples from tumors while the yellow dots are “labeled ” as healthy. So we could use supervised learning to predict whether a new sample is from a healthy or not healthy sample. According to where the new sample is situated in the space we could predict from which type of sample it came from. If it’s situated on the right side it comes from a sick sample and if it’s situated on the left it is healthy. However, there are usually thousands of samples and more than 2 gene expression profiles tested making our raw data matrix multidimensional and more complicated.</p><h3>Classifying Algorithms</h3><p>We have labeled data set, what algorithms can we use? Decision trees, KNN (K Nearest Neighbors), SVM (Support Vector Machine), NN (Neural Networks), and many more… Which algorithm you use depends on how the raw data is structured.</p><p>Decision trees: If your data shows complexity, decision trees will work well and it’s usually easier to grasp the dividing rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*06R2PniF7rdQ1PYTB9whRw.png" /><figcaption>Decision tree — Example from medicine</figcaption></figure><p>SVM: In SVM we find a hyperplane that divides the space into two, the space can be multidimensional and the function that divides our data does not have to be linear. This algorithm can’t always perfectly classify using our training set so you will have to choose the best separation. Also, the further away the sample is from the function the more confidence we have in the classification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*vc8i0kbvR-PYfAAD36xXMg.png" /></figure><p>KNN: classifies a new sample by the ‘K’ amount of samples around it. This algorithm works locally and tests only in the sample’s immediate area. The main advantage of using this algorithm is the fact it allows us to analyze data sets that are very complex and hard to explain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*kgW-gH87BYRVSIOG2LpV2Q.png" /></figure><h3>Performance Evaluation</h3><p>Because different algorithms will behave differently between different data sets, we have to evaluate our classifier that was created. To do so we divide the data set into smaller data sets and check how it performs on one of them (the “testing set”). We then measure the classifier’s success by checking its accuracy, sensitivity, and specificity on the rest of the data (“training” set).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*tvGnsZDFs_PYvI1deeH31g.png" /></figure><p>Accuracy = (TP+TN)/(TP+TN+FP+FN), Sensitivity = TP/(TP+FN), Specificity = TN/(FP+TN). Sadly there will always be trade-offs between how sensitive, accurate and specific our algorithm will be so it’s up to you as a scientist to decide which is more important. While we train the algorithm we need to be careful and avoid overfitting our algorithm to one training set, the way we make sure we don’t overfit our algorithm is by performing cross-validation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7N8RlNJRk4s9oJAIAVGraQ.png" /></figure><h4>Cross-validation</h4><p>In cross-validation, we create several different testing sets from our entire data set. This creates different training sets within our data to evaluate the performance of the algorithms. You can test different models, summarize the overall performance (sensitivity, accuracy, and specificity) for every training and pick the best one.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc71e9fe196f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Map This]]></title>
            <link>https://gal-gilor.medium.com/map-this-549c8efc37b6?source=rss-9a2fa2a33f07------2</link>
            <guid isPermaLink="false">https://medium.com/p/549c8efc37b6</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Gal Gilor]]></dc:creator>
            <pubDate>Tue, 23 Jul 2019 16:42:04 GMT</pubDate>
            <atom:updated>2019-09-29T00:43:55.304Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*fuUq-OGDi1xOF6lVrJ95cg.gif" /></figure><p>Today I would like to discuss the map function in Python. How to use it, why I usually prefer using it instead of a regular For loops, and introducing list comprehensions.</p><p>To make sure I get my point across I will cover a few basics first. Hopefully, this post will also be approachable to people with little Python experience.</p><h4>Iterables</h4><p>Iterables can be different types of ordered lists, in general, we call those lists that contain information in a set order — “Arrays”.</p><h3>Map Function</h3><p>The map function executes a specified function for each item in an array.</p><p><strong>Python Syntax</strong></p><blockquote>map(function, iterables)</blockquote><h4>Returns</h4><blockquote>Returns a list of the results after applying the given function to each item of a given <a href="https://www.programiz.com/python-programming/iterator">iterable</a> (more detailed explinations about iterables).</blockquote><h3>For Loop</h3><p>For loops are basic constructs in programming that run a piece of code repeatedly while certain conditions are met. Most programming languages contain one or more types of those looping constructs so this is familiar to anyone who knows a different programming language.</p><p><strong>Python Syntax</strong></p><blockquote>for item in list:</blockquote><p>Keywords being <em>for </em>and <em>in </em>Followed by a colon. With the next line containing the code you want to run indented. Failing to adhere to the syntax will result in errors and frustration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*f5lY59hRPHi6FCdbeUvwuw.gif" /></figure><h3>List Comprehension</h3><p>In layman terms, list comprehension is a one-line for loop for the specific task of creating a new array. Many programmers prefer list comprehensions over regular for loops because it’s shorter. However, shorter isn’t always more readable. Especially when adding a conditional statement. Overall, I find list comprehensions especially useful when I don’t need to apply more than one function or a conditional. It’s efficient and I highly recommend people to experiment with those more.</p><h4>Syntax</h4><blockquote>new_list = [ expression for item in items if condition ]</blockquote><h3>Examples</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc3146230f8524a4d011fc4ce02a5757/href">https://medium.com/media/dc3146230f8524a4d011fc4ce02a5757/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1680d3faca00f377707d5ad05e087a0a/href">https://medium.com/media/1680d3faca00f377707d5ad05e087a0a/href</a></iframe><p>I’ve created a list of numbers and a function that multiplies a number times 3. Using the numbers list, I want to create a new list where each number is a number from the original list times 3.</p><p>In all the examples, we iterate over every number in the original numbers list, multiply the numbers times 3 and save it in a new list*.</p><p><em>*I want to note that the map function returns an “object”, not a list. If you’re unsure about the different variable types in python I’d recommend </em><a href="https://www.tutorialspoint.com/python/python_variable_types.htm"><em>clicking here</em></a><em>. To get the desired output I used the list function. Typically, the map function is used alongside other functions (e.g filter, reduce, and lambda functions). Unfortunately, I’m not going to explain the filter and reduce functions in this post.</em></p><h3>Lambda Expressions</h3><h4>Syntax</h4><blockquote>(lambda &lt;variables&gt;: &lt;function&gt;)</blockquote><p>In the above examples, I also used the lambda function. Lambda also called an “anonymous function”, is a nameless, user-defined function. Just like regular functions, lambdas can contain any number of arguments. However, you’ll want to keep your lambdas short to maintain readability. The above example may be overly simplistic, however, the lambda function is a strong tool in a programmer’s toolbox. I highly recommend new programmers to do their research before they dismiss it (<a href="https://stackoverflow.com/questions/890128/why-are-python-lambdas-useful">why are python lambdas useful</a>).</p><h3>Summary</h3><p>I often find myself drawn to the map function instead of for loops because I find it shorter and more readable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*KVUlDagoIDVAGT-k1oWavA.jpeg" /></figure><p>In many cases when you’re trying to incorporate several functions inside a for loop the code can get more complicated. The map function along with other functions helps keep things simpler while not having to settle about readability. You can introduce the map function inside a for loop to avoid nested structures and additional syntax errors due to faulty indentation. Additionally, the map function helps you protect the original data in case you need to use it again in your code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*WrB1JYkUP9znbCC0uYhK4Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*Z78BRshvICMMg0HMX2Nqng.jpeg" /></figure><p>Sadly, I have not found a comprehensive study that compares for loops and map function’s performance (p<em>lease comment below if you have!</em>). Although, from different tests people performed, it seems for loops are slightly more efficient than the map function. However, both of them are very inefficient in comparison to vectorization.</p><p>At the end of the day, programming is similar to writing a story. It’s common to see two different people conveying the same message using different words and expressions. Despite map function not being as efficient as for loops in terms of computer performance, it is a tool worth mastering. I often use it to avoid nested structures in my code as the difference in performance is negligible.</p><h3>References</h3><ul><li><a href="https://www.tutorialspoint.com/python/python_variable_types.htm">Python - Variable Types</a></li><li><a href="https://www.programiz.com/python-programming/iterator">Python Iterators</a></li><li><a href="https://thepythonguru.com/python-lambda-function/">Python Lambda Function - The Python Guru</a></li><li><a href="https://stackoverflow.com/questions/890128/why-are-python-lambdas-useful">Why are Python lambdas useful?</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=549c8efc37b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>