<?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 Perul Jain on Medium]]></title>
        <description><![CDATA[Stories by Perul Jain on Medium]]></description>
        <link>https://medium.com/@peruljain?source=rss-4400006f232------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*5lkWjobTUgja8yVB.</url>
            <title>Stories by Perul Jain on Medium</title>
            <link>https://medium.com/@peruljain?source=rss-4400006f232------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 09:03:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@peruljain/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[Java Streams]]></title>
            <link>https://medium.com/@peruljain/java-streams-300899e1f9fd?source=rss-4400006f232------2</link>
            <guid isPermaLink="false">https://medium.com/p/300899e1f9fd</guid>
            <category><![CDATA[java-stream-api]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Perul Jain]]></dc:creator>
            <pubDate>Sun, 07 Jan 2024 08:53:54 GMT</pubDate>
            <atom:updated>2024-01-07T08:53:54.795Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*0VX7zQELEa4d1ze3.jpg" /></figure><p>We are extensively integrating Java Streams into our daily coding practices without delving into the internals workings of streams. Java Streams prove particularly beneficial for processing larger datasets but not extensive beneficial for smaller dataset . We aim to explore the nuances of Java Streams and it’s various operations.</p><h3>What is Java Stream ?</h3><p>A Stream in Java is a sequence of elements supporting sequential and parallel aggregate operations. Think of it as a conveyor belt in a factory where elements (data) move along, and various operations (like filtering, sorting, etc.) can be performed on them.</p><p>It’s important to understand that a stream doesn’t store data. It simply conveys data from a source (like a collection or an array) through a pipeline of computational steps.</p><p>Let’s clarify this with an example. Imagine you have a list of numbers ranging from 1 to 10000. Your task is to identify the even numbers or the numbers that are perfect squares.</p><p><strong>Without Java Streams API</strong></p><pre>for (Integer value : list) {<br>    if(value % 2 == 0) {<br>        ans.add(value);<br>    } else if(isPerfectSquare(value)) {<br>        ans.add(value);<br>    }<br>}</pre><p><strong>With Java Streams API</strong></p><pre>List&lt;Integer&gt; ans = list.stream()<br>                        .filter(value -&gt; value % 2 == 0 || isPerfectSquare(value))<br>                        .collect(Collectors.toList());</pre><h3>Phases of Stream</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/0*KuvaRegAy9OqvDh1.png" /></figure><p><strong>Creation</strong>: A stream is created from a source, which can be a collection, an array, a generator function, or an I/O channel. For example, you can create a stream from a list using list.stream().</p><p><strong>Intermediate Operations</strong>: These operations are applied on the stream and return a new stream. They are lazy, meaning they don’t start processing the elements until a terminal operation is invoked. Common intermediate operations include filter (filters elements based on a predicate), map (transforms each element into another form), sorted (sorts the elements), and distinct (removes duplicates).</p><p><strong>Terminal Operations</strong>: These operations produce a result or a side-effect. Once a terminal operation is performed, the stream can no longer be used. Common terminal operations include forEach (performs an action for each element), collect (transforms the stream into a different form, like a List or a Set), reduce (combines elements to produce a single summary result), and count (returns the number of elements).</p><p><strong>Short-circuiting Operations</strong>: Some operations, like findFirst or anyMatch, do not need to process the entire stream to produce a result. They are called short-circuiting operations because they can terminate early.</p><p>Remember, streams are designed to be used just once. After a terminal operation has been performed, the stream pipeline is considered consumed, and no further operations can be performed on it.</p><pre>import java.util.Arrays;<br>import java.util.List;<br>import java.util.stream.Collectors;<br><br>public class StreamExample {<br>    public static void main(String[] args) {<br>        List&lt;String&gt; myList = Arrays.asList(&quot;delhi&quot;, &quot;udaipur&quot;, &quot;dehradun&quot;, &quot;jaipur&quot;);<br><br>        List&lt;String&gt; filteredList = myList.stream() // Creation<br>                .filter(s -&gt; s.startsWith(&quot;d&quot;)) // Intermediate Operation<br>                .map(String::toUpperCase) // Intermediate Operation<br>                .collect(Collectors.toList()); // Terminal Operation<br><br>        System.out.println(filteredList);<br>    }<br>}</pre><h3>Stream Internal Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*Y748RkEz9Ak1xitFmWYX6g.png" /></figure><p><strong>LinkedList Structure:</strong></p><ol><li>Java Streams use a LinkedList-like structure to store a chain of stream operations.</li><li>Each node in this linked list represents an operation applied to the stream (like filter, map, sorted).</li><li>The stream starts from a source (like a collection), and each subsequent operation is added as a new node in the list.</li></ol><p><strong>Bitmap Flags</strong></p><ol><li>Each stage (or node) in the stream’s internal linked list is assigned a set of bitmap flags. These flags represent certain characteristics or optimizations applicable to that stage.</li><li>The flags include SIZED, DISTINCT, SORTED, and ORDERED.<br>These <strong>flags</strong> help the stream framework to <strong>optimize the execution plan</strong> and make decisions about how to best process the stream.</li></ol><p><strong>Meaning of Flags</strong></p><ul><li><strong>SIZED</strong>: Indicates that the size of the stream is known. This is useful for optimization, especially when creating new collections from the stream.</li><li><strong>DISTINCT</strong>: Implies that the elements in the stream are unique. This can be used to avoid unnecessary checks for duplicates.</li><li><strong>SORTED</strong>: Means that the elements in the stream are sorted. This is important for operations that depend on the order, like limit or skip.</li><li><strong>ORDERED</strong>: Indicates whether the stream has a meaningful encounter order. In ordered streams, the order in which elements are encountered should be preserved.</li></ul><p>The above concepts are quite theoretical; let’s try to clarify them with some practical examples.</p><pre>Set&lt;String&gt; cities = new HashSet&lt;&gt;(Arrays.asList(&quot;udaipur&quot;, &quot;jaipur&quot;, &quot;delhi&quot;, &quot;hariyana&quot;, &quot;dehrandun&quot;));<br><br>List&lt;String&gt; stream = cities.stream()<br>                                   .distinct() // This operation can be skipped<br>                                   .map(String::toUpperCase)<br>                                   .toList(); <br></pre><p>When we call .distinct() on the stream, the stream is able to recognize that the source is a Set and thus already contains distinct elements. The internal optimization flags (like the ones we discussed earlier) allow the stream to skip the distinct operation entirely, as it’s redundant.</p><h3>Stream Execution</h3><p><strong>Lazy Execution:</strong></p><ol><li>Java Streams are “lazily executed”. This means that they don’t actually perform any computation until a terminal operation (like collect, forEach, reduce) is invoked.</li><li>The intermediate operations (like map, filter, flatMap) just define the pipeline and are only executed when the terminal operation triggers the processing.</li></ol><p><strong>Stateless vs. Stateful Operations:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*NPFbkpR4soLsLhOFsY0_5g.png" /></figure><ol><li>Stateless Operations: These operations, such as filter, map, or flatMap, do not retain state from previously processed elements. They can process each element independently.</li><li>Stateful Operations: In contrast, operations like sorted, limit, or distinct are stateful. They need information about other elements in the stream to produce a result. For example, sorted needs to see all elements to sort them.</li></ol><p>The above concepts are quite theoretical; let’s try to clarify them with some practical examples.</p><p><strong>Example 1 :</strong></p><pre>List&lt;String&gt; cities = List.of(&quot;delhi&quot;, &quot;udaipur&quot;, &quot;jaipur&quot;, &quot;dehradun&quot;);<br><br>        List&lt;String&gt; filteredCities = cities.stream()<br>            .filter(city -&gt; {<br>                System.out.println(&quot;filter : &quot; + city);<br>                return city.startsWith(&quot;d&quot;);<br>            })<br>            .map(city -&gt; {<br>                System.out.println(&quot;map : &quot; + city);<br>                return city.toUpperCase();<br>            })<br>            .toList();</pre><p>From the code provided above, one might assume that the list is first filtered and then the map operation is applied. However, that is not necessarily how it works.</p><p>Since both filter and map operations are stateless, they process each element independently.</p><p>Now let see output of above code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*du0p0Ii9b97aTrt9KyQpWg.png" /></figure><p>As observed, each element is processed independently, with the filter and map operations being applied to each element separately.</p><p><strong>Example 2 :</strong></p><pre>List&lt;String&gt; cities = List.of(&quot;delhi&quot;, &quot;udaipur&quot;, &quot;jaipur&quot;, &quot;dehradun&quot;);<br> <br>List&lt;String&gt; filteredCities = cities.stream()<br>            .filter(city -&gt; {<br>                System.out.println(&quot;filter : &quot; + city);<br>                return city.startsWith(&quot;d&quot;);<br>            })<br>            .distinct()<br>            .map(city -&gt; {<br>                System.out.println(&quot;map : &quot; + city);<br>                return city.toUpperCase();<br>            })<br>            .toList();</pre><ol><li>The filter and map operations process each element independently.</li><li>The distinct operation does not process each element independently, as it relies on the state of previously processed elements to function correctly.</li></ol><p>The combination of stateful and stateless operations in this stream means that while some elements (like those being filtered and mapped) are processed independently,<strong> the overall stream processing is not entirely independent due to the stateful nature of the distinct operation.</strong></p><p><strong>Example 3 :</strong></p><pre>List&lt;String&gt; cities = List.of(&quot;delhi&quot;, &quot;udaipur&quot;, &quot;jaipur&quot;, &quot;dehradun&quot;);<br><br>List&lt;String&gt; filteredCities = cities.stream()<br>            .filter(city -&gt; {<br>                System.out.println(&quot;filter : &quot; + city);<br>                return city.startsWith(&quot;d&quot;);<br>            })<br>            .map(city -&gt; {<br>                System.out.println(&quot;map : &quot; + city);<br>                return city.toUpperCase();<br>            })<br>            .sorted()<br>            .toList();</pre><p>Output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*yoM5FbHWNDNG5Tv8E2h7WQ.png" /></figure><p>In the example provided, both map and filter are stateless operations. Therefore, they are applied independently to each element. Subsequently, sorting is applied, which is a stateful operation.</p><p><strong>Example 4 :</strong></p><pre>List&lt;String&gt; cities = List.of(&quot;delhi&quot;, &quot;udaipur&quot;, &quot;jaipur&quot;, &quot;dehradun&quot;);<br><br>List&lt;String&gt; filteredCities = cities.stream()<br>            .filter(city -&gt; {<br>                System.out.println(&quot;filter : &quot; + city);<br>                return city.startsWith(&quot;d&quot;);<br>            })<br>            .sorted()<br>            .map(city -&gt; {<br>                System.out.println(&quot;map : &quot; + city);<br>                return city.toUpperCase();<br>            })<br>            .toList();<br><br> System.out.println(&quot;sorted list : &quot; + filteredCities);</pre><p>Output :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*Wsu1Sqc-gNKudgD2PW3igQ.png" /></figure><p>The output above demonstrates that initially, all elements undergo a filtering process. Subsequently, the remaining elements are mapped and finally sorted.</p><ol><li>The main difference is the order of the map and sorted operations. In example 3 , cities are sorted in their original (lowercase) form and then converted to uppercase. In Example 4, cities are first converted to uppercase and then sorted</li><li>This leads to a potential difference in the sorting order. Since sorting is case-sensitive, the uppercase conversion before sorting in Example 4 can lead to a different order compared to Example 3.</li></ol><h3>Parallel Streams</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*PO9OUa6znsD6L_QFT53Fag.png" /></figure><ul><li>Parallel streams split the data into multiple chunks, processing them in parallel threads.</li><li>They utilize the Fork/Join framework in Java, which allows tasks to be split into smaller tasks and then combined (joined) to produce a result.</li></ul><p>The above concepts are quite theoretical; let’s try to clarify them with some practical examples.</p><p><strong>Example 1 :</strong></p><pre>List&lt;String&gt; cities = List.of(&quot;delhi&quot;, &quot;udaipur&quot;, &quot;jaipur&quot;, &quot;dehradun&quot;);<br><br>List&lt;String&gt; filteredCities = cities.parallelStream()<br>            .filter(city -&gt; {<br>                System.out.println(&quot;Thread : &quot; + Thread.currentThread().getName() + &quot; filter : &quot; + city);<br>                return city.startsWith(&quot;d&quot;);<br>            })<br>            .map(city -&gt; {<br>                System.out.println(&quot;Thread : &quot; + Thread.currentThread().getName() +  &quot; map : &quot; + city);<br>                return city.toUpperCase();<br>            })<br>            .toList();<br><br>System.out.println(&quot;sorted list : &quot; + filteredCities);</pre><p>Output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0wUomQnI_I1BO7Yh_qCMYQ.png" /></figure><p><strong>parallelStream()</strong> is called on the cities list. This creates a parallel stream, which means the stream operations can be executed in parallel across multiple threads.</p><p>In our example, it’s possible that:</p><ul><li>The filter operation for a particular city (like &quot;delhi&quot;) could be executed in one thread.</li><li>The subsequent map operation for the same city could be executed in a different thread.</li></ul><p>This behavior is part of what makes parallel streams powerful, as it allows for the efficient utilization of multiple cores of the CPU, potentially speeding up the processing of large collections of data.</p><p>However, for small data sets or less complex operations, parallel processing might be slower due to the overhead of managing multiple threads.</p><h3>Points to Consider Before Using Java Streams<strong> ?</strong></h3><ol><li><strong>Performance Overhead</strong>: For small collections or simple operations, the overhead of creating a Stream might not justify its benefits compared to traditional loops.</li><li><strong>Debugging Difficulty</strong>: Debugging a chain of Stream operations can be more challenging compared to traditional imperative code structures.</li><li><strong>Readability Issues</strong>: While Streams can make code more concise, they can also make it less readable, especially for those not familiar with functional programming concepts.</li><li><strong>Memory Consumption</strong>: Intermediate operations in Streams can consume more memory, as they may need to maintain the state of the data being processed.</li></ol><h3><strong>Conclusion</strong></h3><p>Java Streams provide an efficient and intuitive framework for processing collections of data. Their ability to perform complex operations through a combination of stateless and stateful methods, along with the flexibility of sequential and parallel processing, makes them an indispensable tool in a Java developer’s life. While they shine in handling large datasets, it’s important to use them judiciously, considering the overhead in smaller data sets or simpler tasks. Understanding their internal workings, particularly for optimization and execution, is key to leveraging their full potential for clean, efficient, and maintainable code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=300899e1f9fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[http1.x vs http2]]></title>
            <link>https://medium.com/@peruljain/http1-x-vs-http2-4ee8d971d97d?source=rss-4400006f232------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ee8d971d97d</guid>
            <category><![CDATA[multiplexing]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[http2]]></category>
            <dc:creator><![CDATA[Perul Jain]]></dc:creator>
            <pubDate>Sun, 26 Nov 2023 06:11:32 GMT</pubDate>
            <atom:updated>2023-12-02T06:02:12.897Z</atom:updated>
            <content:encoded><![CDATA[<h3>http1.1 vs http2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ClBfD5h_Yt2slQ2wFs1SIA.png" /></figure><p>As observed in the preceding example, In this article we’ll explore the speed difference between HTTP/2 and HTTP/1.1 . We aim to comprehend the reasons behind the increased speed of HTTP/2 and examine the additional features it offers compared to HTTP/1.1</p><h3>What is HTTP ?</h3><p>If you are new to HTTP then continue to read this block otherwise you can<br>skip below paragraph</p><p><strong>HTTP</strong>, which stands for Hypertext Transfer Protocol, serves as the foundation for nearly all web applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GKn_3VPbscyDJQMgBB6usg.png" /></figure><p><strong>HTTP is based on</strong> the Client/Server model. Client/Server model can be explained as two computers, Client (receiver of service) and Server (provider of service) that are communicating via requests and responses.</p><h3>How http1.1 works ?</h3><p><strong>Connection Establishment </strong><br>Before any communication takes place, a TCP connection will be established between the client and the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*jnhelbhF2DuUQ8jB1grLTA.png" /></figure><p><strong>Request Message<br></strong>After TCP Connection establishment , Client will send http request like. below</p><pre>GET /index.html HTTP/1.1<br>Host: www.example.com<br>User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36</pre><p><strong>Server Processing <br></strong>The server receives the request, processes it, and generates the response.</p><pre>HTTP/1.1 200 OK<br>Date: Thu, 01 Dec 2023 12:00:00 GMT<br>Content-Type: text/html; charset=utf-8<br><br>&lt;html&gt;<br>&lt;body&gt;<br>&lt;h1&gt;Hello, World!&lt;/h1&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Connection Closure<br></strong>After the response is sent, the server may close the connection or keep it open for further requests (using techniques like persistent connections to improve performance).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*zXeympCbz3KxlD4_wWiQGA.png" /></figure><h3>Limitations of http1.1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*tW5DWkh6czD2ooYMfH727w.png" /></figure><p>As depicted in the above diagram, to load index.html and styles.css, we must initiate a GET request for index.html first, followed by a GET request for script.js. Since these two GET requests occur sequentially, if the GET request for index.html takes time to respond, we are unable to make the GET request for script.js within the same TCP connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*trTBl5IYg9I-gbEqlUJfKQ.png" /></figure><p>If you are accessing the website <a href="http://www.example.com/">www.example.com</a>, where the loading of three files — jquery.js, jexample.css, and image.png — is required. If you aim to retrieve all <strong>three files parallel</strong>, it is not possible within the same TCP connection. Consequently, you must establish three separate TCP connections with the server to retrieve the essential files .</p><p><strong>Moreover, it’s important to note that there are restrictions on the number of TCP connections that each browser can establish with the domain.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*voxG9IpsEhJGtMoUG1FEuQ.png" /></figure><p>HTTP/1.1 also introduced pipelining, which allows multiple HTTP requests to be sent over a single TCP connection without waiting for the corresponding responses.</p><p>With pipelining there is one issue which called as <strong>head of line blocking</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ePJxv-q4jDpgxzwUU1q9lQ.png" /></figure><p>If, for any reason, response1 cannot be sent to the client, it will stop the transmission of response2 until response1 is retransmitted.</p><h3>How http2 is different from http1.x ?</h3><p>The major feature that differentiates HTTP/2 from HTTP/1.1 is the binary framing layer. Unlike HTTP/1.1, HTTP/2 uses a binary framing layer. This layer encapsulates messages — converted to its binary equivalent — while making sure that its HTTP semantics (method details, header information, etc.) remain untamed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*I0qS_IM1HZxzXap5ZjVkbA.png" /></figure><p>HTTP/1.1 sends messages as plain text, and HTTP/2 encodes them into binary data and arranges them carefully.</p><h4>Binary Framing Layer</h4><p>To get better understanding of binary framing layer which is used for exchanged data between client and server . we need to understand few important terms : streams, messages and frames</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*JQrVW4v8PpAsrSXTeI_pEg.png" /></figure><p><strong>Frame</strong> : The smallest unit of communication in HTTP/2, each containing a frame header, which at a minimum identifies the stream to which the frame belongs.<br><strong>Message</strong> : A complete sequence of frames that map to a logical request or response message.<br><strong>Stream : </strong>A bidirectional flow of bytes within an established connection, which may carry one or more messages.</p><h4>How http2 solving the limitations of http1.1 ?</h4><h4><strong>Request Multiplexing</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YL1SpW_IeBEk3RoCROpCtw.png" /></figure><p>In the example above, you can observe that when loading four resources in a browser, it is possible to initiate four parallel GET requests within the same TCP connection. Each GET request essentially functions as a stream. Subsequently, the server will respond with the same stream ID that was provided in the initial request.</p><p>If you are using HTTP/1.1 without pipelining, you must either send four GET requests sequentially, or create four separate TCP connections to send the four GET requests simultaneously.</p><h4>Server Push</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8NYi25XCSraT8-UOX2q1GQ.png" /></figure><p>If you intend to load the “index.html” file in a browser, and it depends on “main.css,” “main.js,” and “img.png,” the server has the capability to push all these resources without requiring individual requests.</p><p>Note: The client must be compatible with HTTP/2, and the server should be configured to enable resource push.</p><h4>Header Compression</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*7DGCzmQHCwPB_q7lR2oEDA.png" /></figure><p>HTTP/2 compresses request and response header metadata using the HPACK compression. This eliminates a few bytes from every HTTP packet. Given the volume of HTTP packets involved in loading even a single webpage, those bytes add up quickly, resulting in faster loading.</p><h4>Stream Prioritization</h4><p>The client can indicate which if the resources are more important than others to a server. For providing the prioritization HTTP2 standards has a feature to provide associated weight and dependency (if the stream is depending on another stream). Consider a web page with an HTML file, CSS file, and several images. The HTML file might have a higher priority since it’s essential for rendering the page. The CSS file could depend on the HTML file, ensuring it is prioritized after the HTML file.</p><pre>- Stream 1 (HTML file, weight 16)<br>|__ - Stream 2 (CSS file, weight 8)<br>|__ - Stream 3 (Image 1, weight 4)<br>|__ - Stream 4 (Image 2, weight 4)</pre><p>The server allocates resources according to the stream priorities, ensuring that higher priority streams get more resources and are delivered more quickly.</p><h3>Conclusion</h3><p>HTTP/2 offers several improvements over HTTP/1.1, particularly in terms of performance and efficiency. The introduction of features like multiplexing, header compression, and server push makes HTTP/2 better suited for the modern web where websites are more complex and resource-intensive. It helps reduce latency, improve page load times, and optimize resource usage.</p><h3>References</h3><ol><li><a href="https://www.cloudflare.com/learning/performance/http2-vs-http1.1/">https://www.cloudflare.com/learning/performance/http2-vs-http1.1/</a></li><li><a href="https://www.youtube.com/watch?v=a-sBfyiXysI">https://www.youtube.com/watch?v=a-sBfyiXysI</a></li><li><a href="https://www.wallarm.com/what/what-is-http-2-and-how-is-it-different-from-http-1">https://www.wallarm.com/what/what-is-http-2-and-how-is-it-different-from-http-1</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ee8d971d97d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Crio.do Microexperience]]></title>
            <link>https://medium.com/@peruljain/crio-do-microexperience-d15efa098526?source=rss-4400006f232------2</link>
            <guid isPermaLink="false">https://medium.com/p/d15efa098526</guid>
            <dc:creator><![CDATA[Perul Jain]]></dc:creator>
            <pubDate>Tue, 07 Jan 2020 09:24:47 GMT</pubDate>
            <atom:updated>2020-01-07T09:24:47.914Z</atom:updated>
            <content:encoded><![CDATA[<p>Many of you don”t aware of what is Crio.do so let me give short Intro.</p><p>Crio empowers developers through work-like Micro- Experiences, with real world problems in an environment optimized for learning and Crio Launch is a unique program from Crio.Do to get internship-like experience, build a portfolio, and land great career opportunities.</p><p>In today’s world everyone uses food ordering app just like zomato,swiggy,uber eats and many more. Every foodapp has feedback option . Let me explain with example</p><p>Suppose I order food from the app and i want to share review on social platform. So what feature we gonna build is this-&gt;we take photo of order food and we share our review on facebook with caption and on pinterest with hashtags of food category.</p><p>Now i will tell you what work we gonna do in this micro-experience.</p><h4>Tech-stack</h4><ul><li>Python programming language</li><li>Django Framework</li></ul><p>Firstly we made facebookPost module. In this module we will have a function for posting photo with caption to facebook. I used facebook graph api for posting message and photo to facebook.</p><p>Second we have to made pinterest module. In this module we have to create pins in our Pinterest board .In this we have to share photo to pinterest board. I used pinterest api for creating pins in Pinterest board.</p><p>Third we have to made TagSuggestion module .In this module we have a image_url of photo . We have to predict tags of given photo.I used clarifai api for this task. Basically this prediction task is machine learning task so I used pre-train food model of clarifai api.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RP8SRZTWibLIvJyUH3ubSQ.jpeg" /></figure><p>As you see above we get wonderful result.</p><p>What I learn from this micro-experience.</p><ul><li>Introduction to Django framework</li><li>Http requests</li><li>Writing clean code.</li></ul><h3>Link</h3><ul><li>http://criodo.mg.criodo.com/c/eJwdjkGKxCAURE9jlvLVaHThYpqQxdDMZg4gRn-nBY3BScj1O5NNUVRRxYsWOComu2Q5cAAGioHoxUAZFf3IHhIeauCjGJUiPZSFhpZqrDTU0r1teM0otZkNNzwMHmcwUupotBwQotBdtud53hsaK-FT9sca3pchYjr24v7q0QISMTZ8YXMb4eo_Dr5sPi3rVXAtNmxds5ceWSh5YSzFp3wj7FZ9f_24533rprT67H4xY9hTXT9QwUR8</li><li>https://www.google.com/url?sa=t&amp;source=web&amp;rct=j&amp;url=https://docs.djangoproject.com/en/3.0/&amp;ved=2ahUKEwievKLylPHmAhWYV30KHaFwDNQQFjADegQIBhAB&amp;usg=AOvVaw0YwHjKuilkjJehZ45Dv1hO</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d15efa098526" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tag Predictor]]></title>
            <link>https://medium.com/analytics-vidhya/tag-predictor-fae407274fa0?source=rss-4400006f232------2</link>
            <guid isPermaLink="false">https://medium.com/p/fae407274fa0</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Perul Jain]]></dc:creator>
            <pubDate>Tue, 24 Dec 2019 12:15:02 GMT</pubDate>
            <atom:updated>2020-01-02T14:24:10.247Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are developer then this problem statement will excite you. As I am a android developer and machine learning enthusiast, I always search some of functions which i forgot and stack overflow will help me on this. Have you ever think that how stack overflow predict tags? Tags are essential because it will send question to expert according to tags.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*uQZZvtnQFFJ-HDglAe1LWQ.gif" /></figure><p><strong>What is stack overflow?</strong></p><p>Stack-overflow is a platform where students and professionals post queries and answer questions about programming. It is a platform to showcase their knowledge. It is owned by the Stack Exchange Network. The answers are up-voted based on its usefulness to the community. Users can also use Stack-overflow to advance their careers. It is a community of more than seven million programmers.</p><p><strong>Problem statement</strong></p><p>We have to predict of posted question on stack-overflow.</p><p><strong>Business objective and constraints</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NkjL-NPmx01vRXd6kIxsGw.png" /></figure><p>Suppose the question “How to change color of button in android when clicked “is asked by any user. Now we want that by given question and description we want to predict some tags. In the above picture tag is android so what stack-overflow ecosystem does is that it will send this question to that person which already answered lot of questions related to android.</p><p>Now you think if predicted tag is irrelevant to question then it will be sent to wrong person so it will impact user experience. Misclassification of tags could lead to huge impact on business.</p><p>No such strict latency constraints means we can take time to predict. Our main goal is to correctly predict the data point.</p><p><strong>Machine Learning Problem Statement</strong></p><p>It is a multi label-classification problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l83Qa0pMphn3AJXlqsWWlg.jpeg" /></figure><p>There is a difference between multi-class classification problem and multi-label classification problem.</p><p><strong>Multi-class classification</strong> means a classification task with more than two classes; e.g., classify a set of images of fruits which may be oranges, apples, or pears. Multi-class classification makes the assumption that each sample is assigned to one and only one label: a fruit can be either an apple or a pear but not both at the same time.</p><p><strong>Multi label classification</strong> assigns to each sample a set of target labels. This can be thought as predicting properties of a data-point that are not mutually exclusive, such as topics that are relevant for a document. A text might be about any of religion, politics, finance or education at the same time or none of these.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*ofA6_DSSUuQzRf9Y4xu8Xw.png" /></figure><p><strong>Performance metric</strong></p><p>The <strong>F1 Score</strong> is the 2*((precision*recall)/(precision+recall))</p><p>Precision is basically out of all the tags predicted, how many of them belongs to the correct class. Recall is Out of all the correct tags of each class there were, how many of them were classified correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*faN6xOgUJ8t-DV4R4DdoSg.png" /></figure><p><strong>Dataset</strong></p><p>Id — unique identifier for each question</p><p>Title — Question’s title</p><p>Body — Body of the question</p><p>Tags — tags associated with the question in a space separated format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*GtnCm2ADU4Yqekp7AfL37g.gif" /></figure><h4><strong>Exploratory data analysis</strong></h4><p>This is the most important part of any machine learning problem. From this we will get to know deeper inside of our data and also extract some new feature from old features.</p><p><strong><em>Using Pandas with sqlite to load data:</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4PSybC9orlXAibcuMULx3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*33vqtuah0JDhTh0x44giBg.png" /></figure><p><strong>Analysis of Tags</strong></p><p>There are some Nan values in Tags column which we have to replace.For simplification I replace with empty string.</p><p>code-snippet</p><pre>df_no_dup.fillna(&quot; &quot;,inplace=True)</pre><p>Number of duplicate rows -&gt; 1827881</p><p>We have to remove Duplicates because it make our model bias.</p><p>Create non-duplicate database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*lBWU2VtHO2oL3nJPd19Udg.png" /></figure><p>Number of Unique_Tags -&gt; 1827881</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*y2Ga_mcVJGHmdPl9Yvol4w.png" /></figure><p>We see in the above plot that some tags are more frequent than others. Let’s see the frequently occurred tags.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*gmXQuAf3drjZoDb7RksFDA.png" /></figure><p>Most of the Tags are programming languages. I already mentioned in introduction that stack-overflow is widely used by developers. Some operating systems are also there such as windows, Linux.</p><p><strong>Number of Tags in question</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*9Nv-zs_0a48yPw4V_ITQWg.png" /></figure><p>Most of the questions have 2 or 3 tags .</p><p><strong>Data preprocessing</strong></p><ol><li>Remove html tags from question just like &lt;br&gt; etc.</li></ol><p>code snippet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*HlHn4618CzRw242mdqI0yA.png" /></figure><p>2. Remove all code from the body.</p><p>3. Remove stop-words except C because it is programming language.</p><p>4. Convert all the characters into lower case and remove special characters from question.</p><p>5. Use snowball stemmer or porter stemmer for stemming.</p><p>code-snippet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CzDUFn0hE6Obs5hJ1jQ-CQ.png" /></figure><p>After preprocessing the dataset looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*kU9iyee1Un2xngiIxaOegA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*EebCJgJ3-ZaM8AwWFcdvOw.gif" /></figure><p><strong>Machine Learning Models</strong></p><p>This is multi label classification problem and now we will try to convert multi label to single label.</p><p><strong>Binary Relevance Technique</strong></p><p>It basically treats each label as a separate single class classification problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/172/1*3JTcP7Asu8QkD1HuWNsSLA.png" /></figure><p>X is a datapoints and Y1,Y2,Y3,Y4 are labels. If X2 and Y1 equal to one means X2 has label Y1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*8BZDvWMrjyZqeqV5L1IRwg.png" /></figure><p>Now the problem is turns to X is a data-point and Yi is label.So problem downs into binary classifier.</p><p><strong>Logistic Regression (One vs Rest-Classifier)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*f0JWdRnznrwlDUckGVcC2Q.jpeg" /></figure><p>Actually in One vs Rest-classifier we trained n-binary classifier and predict class label of data point by confidence interval or majority voting algorithm.</p><p>The Multi-label algorithm accepts a binary mask over multiple labels. The result for each prediction will be an array of 0s and 1s marking which class labels apply to each row input sample</p><p>code-snippet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*bgG3hRo2vXTCiAZ_fHCgww.png" /></figure><p>you can also try various other techniques like classifier chain,label power set.</p><p><strong>Conclusions:</strong></p><ol><li>I spend most of time in preprocessing of text.</li><li>I take top 15% most used tags and use these tags for machine learning models.</li><li>I make three different databases during preprocessing otherwise it will take 3–4 hours for running Jupyter notebook again.</li></ol><p><strong>References</strong></p><ul><li><a href="https://towardsdatascience.com/journey-to-the-center-of-multi-label-classification-384c40229bff">Deep dive into multi-label classification..! (With detailed Case Study)</a></li><li><a href="https://www.analyticsvidhya.com/blog/2017/08/introduction-to-multi-label-classification/">Solving Multi-Label Classification problems (Case studies included)</a></li><li><a href="https://towardsdatascience.com/multi-class-text-classification-with-scikit-learn-12f1e60e0a9f">Multi-Class Text Classification with Scikit-Learn</a></li><li><a href="https://www.kaggle.com/c/facebook-recruiting-iii-keyword-extraction/data">Facebook Recruiting III - Keyword Extraction</a></li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FnNDqbUhtIRg%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DnNDqbUhtIRg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FnNDqbUhtIRg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b21b70d49b7bdca36219a85a84e94a5/href">https://medium.com/media/3b21b70d49b7bdca36219a85a84e94a5/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fae407274fa0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/tag-predictor-fae407274fa0">Tag Predictor</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[Question Pair Similarity]]></title>
            <link>https://medium.com/analytics-vidhya/question-pair-similarity-be19f3fee6a4?source=rss-4400006f232------2</link>
            <guid isPermaLink="false">https://medium.com/p/be19f3fee6a4</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <dc:creator><![CDATA[Perul Jain]]></dc:creator>
            <pubDate>Tue, 17 Dec 2019 23:20:56 GMT</pubDate>
            <atom:updated>2020-01-31T04:33:10.880Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z-COq9ZHW8x_KI_hpUj4gw.jpeg" /></figure><p>Over 100 million people visit Quora every month, so it’s no surprise that many people ask similarly worded questions. Multiple questions with the same intent can cause seekers to spend more time finding the best answer to their question and make writers feel they need to answer multiple versions of the same question. This is a bad user experience for both writers and seekers, as the answers get fragmented across different versions of the same question. In fact, this is a problem which is very evident on other social Q&amp;A platforms like Stack Overflow. A real-world problem out there, begging AI to solve it :)</p><p><strong>Problem Statement</strong></p><p>Identify the question asked on Quora are duplicates of questions that have already been asked.</p><p>Till now we see the business problem statement and constraints but guys we have to solve problem using machine learning so we have to convert business problem statement to machine learning problem statement.So what we want to predict that two questions are similar or not.</p><p>So machine learning problem statement as follows:</p><blockquote><em>“This is binary classification problem , for a given pair of questions we need to predict if they are duplicate or not with the performance metric (Log-loss)”</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*AaE0H4wpT-REWBEpKrH6LQ.jpeg" /></figure><p>Now lets begin to work upon problem statement.</p><h3>Let`s begin….</h3><h3>Exploratory data analysis</h3><p>This is the very first important part to any machine learning problem. It gives deeper understanding of the dataset and helps to add some new features according to requirement of problem statement.</p><p>We start our EDA by loading the dataset first.</p><p>We are given a minimal number of data fields here, consisting of:</p><ul><li>id: Looks like a simple row-ID</li><li>qid{1, 2}: The unique ID of each question in the pair</li><li>question{1, 2}: The actual textual contents of the questions.</li><li>is_duplicate: The label that we are trying to predict — whether the two questions are duplicates of each other.</li></ul><p><strong><em>Distribution of data points among output classes</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*ewIrqHQCUqPby8SEKqI6iQ.png" /></figure><p>As we can see above that approx 63 percent questions pair are not duplicate and 36 percent questions pair are duplicate.</p><p><strong><em>Number of occurrences of each question</em></strong></p><p>Maximum number of times a single question occurs is 157.</p><h3>Preprocessing of Text</h3><ol><li>Removing html tags</li><li>Removing Punctuation</li><li>Performing stemming</li><li>Removing Stop words</li></ol><p>Stop-words means the words which are occur frequently . for removing stop-words we use nltk library .</p><p>Stemming means the process of converting the words of a sentence to its non-changing portions. In the example of amusing, amusement, and amused above, the stem would be amus.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*89e0WU6VMUXuOvDL7LyG1w.png" /></figure><p>This technique is just like detective sherlock homes.you have to become detective for extracting features . Sometime domain expert will tell you that add these new features but if there is new problem then you have to extract features by your own.For this problem I take reference from kaggle that what features are important and I explain below.</p><p>Definition:</p><p>Token: You get a token by splitting sentence a space</p><p>Stop_Word: stop words as per NLTK.<br>Word : A token that is not a stop_word</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*GtnCm2ADU4Yqekp7AfL37g.gif" /></figure><h3>Features:</h3><ol><li>cwc_min : Ratio of common_word_count to min length of word count of Q1 and Q2.</li><li>cwc_max : Ratio of common_word_count to max length of word count of Q1 and Q2.</li><li>csc_min : Ratio of common_stop_count to min length of stop count of Q1 and Q2.</li><li>csc_max: Ratio of common_stop_count to max length of stop count of Q1 and Q2.</li><li>ctc_min: Ratio of common_token_count to min length of token count of Q1 and Q2.</li><li>ctc_max : Ratio of common_token_count to max length of token count of Q1 and Q2.</li><li>last_word_eq : Check if lastword of both questions is equal or not.</li><li>first_word_eq : Check if First word of both questions is equal or not.</li><li>abs_len_diff : Abs. length difference.</li><li>mean_len: Average Token Length of both Questions</li><li>longest_substr_ratio : Ratio of length longest common sub string to min length of token count of Q1 and Q2.</li><li>FuzzyWuzzy is a library of Python which is used for string matching. Fuzzy string matching is the process of finding strings that match a given pattern.</li></ol><p><strong>WordCloud</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*q_flGUPBBBPaWCkL5_Clfg.png" /></figure><p>As you see that the words which are bigger means that will occur more.</p><p><strong>Let’s plot pairplot and see how our features behave.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*UTosmHZ54JoAy-LzWJuJxw.png" /></figure><p>We can see that blue and orange points are separated. There is some-overlap but we can consider it as a good features and try random model on top it and extract important features.</p><p>Now we have 15 features . Let’s see how points see in 2d plot.we use dimension reduction technique t-SNE( <strong>T</strong>-distributed Stochastic Neighbor Embedding).</p><p>t-SNE -&gt; It is a non-linear dimensionality reduction algorithm used for exploring high-dimensional data. It maps multi-dimensional data to two or more dimensions suitable for human observation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*wnOjj_Wk-45MkfZ_fYQgZg.png" /></figure><p>As we can see that in some parts red points and blue points are separable.So we conclude that the features we build are good for modeling.For better performance we can add more features if required.</p><h4>Featurizing text data with TF-IDF weighted word-vectors</h4><p>There are various techniques to convert text into vector such as bag of words, TF-IDF, avg w2v etc. Here we used tfidf weighted w2v.</p><p>Now let me explain TF-IDF</p><p><strong>TF-IDF</strong> stands for “Term Frequency — Inverse Data Frequency”.</p><p><strong>Term Frequency (tf)</strong>: gives us the frequency of the word in each document in the corpus.</p><p><strong>Inverse Data Frequency (idf): </strong>used to calculate the weight of rare words across all documents in the corpus.</p><p>Word2vec is an algorithm used to produce distributed representations of words, and by that we <strong>mean</strong> word types; i.e. any given word in a vocabulary, such as get or grab or go has its own word vector, and those vectors are effectively stored in a lookup table or dictionary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OEmWDt4eztOcm5pr2QbxfA.png" /></figure><p>As you see that semantic words has close vector representation.</p><p>Now real fun begins….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/1*NF01uqOgORrLaNQ3HNxxDA.gif" /></figure><p><strong>Machine Learning models</strong></p><p>First we try Random model for getting worst case log-loss.</p><pre>predicted_y = np.zeros((test_len,2))<br>for i in range(test_len):<br>    rand_probs = np.random.rand(1,2)<br>    predicted_y[i] = ((rand_probs/sum(sum(rand_probs)))[0])</pre><p>As we find the random model gives log-loss 0.88 . Now we try various linear models and try to achieve log-loss as far less than 0.88.</p><p>Now we try Logistic regression model for classification problem</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y-Sn5LfxHVyRrByuCYXA8A.png" /></figure><pre>For values of alpha = 1e-05 The log loss is: 0.592800211149<br>For values of alpha = 0.0001 The log loss is: 0.532351700629<br>For values of alpha = 0.001 The log loss is: 0.527562275995<br>For values of alpha = 0.01 The log loss is: 0.534535408885<br>For values of alpha = 0.1 The log loss is: 0.525117052926<br>For values of alpha = 1 The log loss is: 0.520035530431<br>For values of alpha = 10 The log loss is: 0.521097925307</pre><p>As we see that for alpha = 1 the log-loss is less.</p><p>So we choose alpha as our <a href="https://en.wikipedia.org/wiki/Hyperparameter_(machine_learning)">hyper-parameter</a>.</p><pre>For values of best alpha = 1 The train log loss is: 0.513842874233<br>For values of best alpha = 1 The test log loss is: 0.520035530431</pre><p>you see that from 0.88 log loss we get into 0.52 log-loss.</p><p>Now we will try linear-Svm model. It almost behaves similarly, but the loss is hinge in linear -SVM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HvPKpMXqpzL1slMXJKstCw.png" /></figure><pre>For values of alpha = 1e-05 The log loss is: 0.657611721261<br>For values of alpha = 0.0001 The log loss is: 0.489669093534<br>For values of alpha = 0.001 The log loss is: 0.521829068562<br>For values of alpha = 0.01 The log loss is: 0.566295616914<br>For values of alpha = 0.1 The log loss is: 0.599957866217<br>For values of alpha = 1 The log loss is: 0.635059427016<br>For values of alpha = 10 The log loss is: 0.654159467907</pre><p>For alpha = 0.0001 we get min log-loss . Now we build model on this aplha.</p><p>Results we got are:</p><pre>For values of best alpha = 0.0001 The train log loss is: 0.478054677285<br>For values of best alpha = 0.0001 The test log loss is: 0.489669093534</pre><p>Now we build some complex model like GBDT. For these we will xgboost instead of sklearn because implementation of xgboost is better than sklearn.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E8q8wpBL0B03SpCJk4WT-g.png" /></figure><p>Random model — 0.88 log loss</p><p>Logistic regression — 0.52 log loss</p><p>Linear -SVM — 0.489 log-loss</p><p>GBDT — 0.357 log-loss.</p><p>Conclusions</p><ol><li>I spent most of the time in analysis and cleaning the data. When data is clean then we have to just write 5–6 lines of code for trying various models.</li><li>Always check that your model would not be over-fit or under-fit by checking performance metric or by plotting ROC Curve.</li></ol><p>Reference Links:</p><ol><li><a href="https://www.kaggle.com/c/quora-question-pairs">https://www.kaggle.com/c/quora-question-pairs</a></li><li><a href="https://www.kaggle.com/anokas/data-analysis-xgboost-starter-0-35460-lb/comments">https://www.kaggle.com/anokas/data-analysis-xgboost-starter-0-35460-lb/comments</a></li><li><a href="https://engineering.quora.com/Semantic-Question-Matching-with-Deep-Learning">https://engineering.quora.com/Semantic-Question-Matching-with-Deep-Learning</a></li><li><a href="https://towardsdatascience.com/identifying-duplicate-questions-on-quora-top-12-on-kaggle-4c1cf93f1c30">https://towardsdatascience.com/identifying-duplicate-questions-on-quora-top-12-on-kaggle-4c1cf93f1c30</a>.</li></ol><p>You can connect with me on Linkedin:</p><p><a href="https://www.linkedin.com/in/perul-jain-55845b154">https://www.linkedin.com/in/perul-jain-55845b154</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*8xyI0OdQwEyx0kEORcbXfA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be19f3fee6a4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/question-pair-similarity-be19f3fee6a4">Question Pair Similarity</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[Exploratory data analysis]]></title>
            <link>https://medium.com/@peruljain/exploratory-data-analysis-5a69c088ed7c?source=rss-4400006f232------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a69c088ed7c</guid>
            <dc:creator><![CDATA[Perul Jain]]></dc:creator>
            <pubDate>Mon, 07 Oct 2019 02:56:30 GMT</pubDate>
            <atom:updated>2019-10-07T02:56:30.668Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part-2</h3><p>In part 1 we discuss various plots mean,median,variance and some basics of PDF and CDF.</p><p>Here is the link of part1</p><p><a href="https://link.medium.com/UseHcBP9p0">https://link.medium.com/UseHcBP9p0</a></p><h4>Now we deep dive into Probability and statistics.</h4><blockquote>Why we learn probability and statistics?</blockquote><p>Let’s understand with example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K2_zu_voGYBx2lhHdqzY0g.jpeg" /></figure><p>Let’s suppose there are three type of flowers -type 1(blue),2(orange),3(green).</p><p>X axis — petal length</p><p>Y axis — petal width</p><p>We can easily separate type1 from type2 and type3 by straight line.but what about type 2 and type 3.The points are too close so what we say by probaility that if we choose any point on x axis with petal length 20cm then 95 percent probability is that it is of type 2 and 5 percent probabilty is of type3.</p><p>Ps):All above values are arbitary for explaination.</p><p>So now you know how probability plays important role in data analysis.</p><h4>Population vs sample</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*9ZlkBbWzUQ1pMYGQqS3zRw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*oXrC23Cwt5LSno56Lm6IPg.jpeg" /></figure><h3>Gaussian /Normal Distribution</h3><p>The normal distribution is arguably the most important concept in statistics. Everything we do, or almost everything we do in inferential statistics, which is essentially making inferences based on data points, is to some degree based on the normal distribution.</p><p>Let”s have a look at mathematical terms</p><p>Gaussian /Normal distribution function represents by N(mu,sigma^2)</p><p>mu is mean and sigma^2 is variance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YXL55Up3gabqJCzJUknQMg.jpeg" /></figure><p>By seeing pdf we see that the less mean graph has high peak and with more variance value the graph is more spread.</p><h4>Now come to the best rule of this graph -&gt;68–95–99.7 Rule</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*__K3H4cgMgHBJCYxw513DQ.png" /></figure><h4>Conclusions</h4><ul><li>Graph is symmetric about mean.</li><li>mu-sigma to mu+sigma has 68 percent probability.</li><li>mu-2sigma to mu+2sigma has 95 percent probability</li><li>mu-3sigma to mu +3sigma has 98 percent probability.</li><li>The total area under the curve of normal distribution is 1.</li></ul><h3>Skewness</h3><p>It is the degree of distortion from the symmetrical bell curve or the normal distribution. It measures the lack of symmetry in data distribution.<br>It differentiates extreme values in one versus the other tail. A symmetrical distribution will have a skewness of 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8bkbtEeV_E99b5hRzJuDLQ.jpeg" /></figure><p>Example:</p><p>Let us take a very common example of house prices. Suppose we have house values ranging from $100k to $1,000,000 with the average being $500,000.</p><p>If the peak of the distribution was left of the average value, portraying a positive skewness in the distribution. It would mean that many houses were being sold for less than the average value, i.e. $500k. This could be for many reasons, but we are not going to interpret those reasons here.</p><p>If the peak of the distributed data was right of the average value, that would mean a negative skew. This would mean that the houses were being sold for more than the average value.</p><h3>Kurtosis</h3><p>Kurtosis is all about the tails of the distribution — not the peakedness or flatness. It is used to describe the extreme values in one versus the other tail. <strong>It is actually the measure of outliers present in the distribution.</strong></p><p>High kurtosis in a data set is an indicator that data has heavy tails or outliers.</p><p>Low kurtosis in a data set is an indicator that data has light tails or lack of outliers</p><h4>MOMENTS</h4><p>Go through this Link</p><p><a href="https://www.thoughtco.com/what-are-moments-in-statistics-3126234%C2%A0">https://www.thoughtco.com/what-are-moments-in-statistics-3126234</a></p><h4>Kernel density function</h4><p>In statistics, kernel density estimation (KDE) is a non-parametric way to estimate the probability density function of a random variable. Kernel density estimation is a fundamental data smoothing problem where inferences about the population are made, based on a finite data sample.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*pgPTjkCHI4yeRswfl9yohQ.png" /></figure><h4>Central Limit Theorem</h4><p>The Central Limit Theorem states that the sampling distribution of the sample means approaches a normal distribution as the sample size gets larger — no matter what the shape of the population distribution.</p><p><strong>Why sample size greater than 30?</strong></p><p>Because our sample size is greater than 30, the Central Limit Theorem tells us that the samplingdistribution will approximate a normal distribution. ... Finding the mean of the sampling distribution is easy, since it is equal to the mean of the population.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*lslCJhk0KrGBJ9nv5MJmrQ.jpeg" /></figure><p>Mean and standard deviation should be finite for applying CLT.</p><h4>How to check that the distribution is Normal?</h4><p>Q-Q plot and k-test are some of the method which is used for check that distribution is normal or not.</p><p>We will Discuss Q-Q plot here and later on we will surely discuss k-test</p><h4>Q-Q plot</h4><p>A Q-Q plot is a scatterplot created by plotting two sets of quantiles against one another. If both sets of quantiles came from the same distribution, we should see the points forming a line that’s roughly straight.</p><p>Let’s see code snippet</p><p>//image of code</p><p>// image of plot</p><h4>Conclusions of above plot</h4><ul><li>If most of the points lie in straight line then Two distributions follow some common distribution.</li><li>In our case it is normal distribution.</li></ul><p>Till now you have idea what is normal distribution and how to check that it is normal distribution .</p><p>But you think that what if distribution is not normal then how will you determine probabilty from pdf because 68–95–98 rules valid for normal distribution only.</p><p>Now chebyshev’s inequality comes into picture.</p><h3>Chebyshev’s inequality</h3><p>Chebyshev’s inequality says that at least 1-1/K^2 of data from a sample must fall within K standard deviations from the mean (here K is any positive real number greater than one).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*G7yopY4LC5YuHhMTv2rA-A.png" /></figure><p><strong>Now let’s discuss some more distributions apart from normal distribution.</strong></p><h4>Discrete distribution vs continious distribution.</h4><p>A discrete distribution is a statistical distribution that shows the probabilities of outcomes with finite values.</p><p>A continuous distribution describes the probabilities of the possible values of a continuous random variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kDacEX8Q7abOkjkSp_NQ0Q.jpeg" /></figure><h3>Bernouli distribution</h3><p>Bernoulli distribution is an independent probability function where a random variable can have only two possible values: either 1 for success or 0 for failure. This is similar to binomial distribution, but for a single yes/no test known as “Bernoulli trials.</p><h3>Binomial distribution</h3><p>A binomial distribution is a specific probability distribution. It is used to model the probability of obtaining one of two outcomes, a certain number of times (k), out of fixed number of trials (N) of a discrete random event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*HE4V_f_nHEOn8v9R44i-tg.jpeg" /></figure><p>Properties of binomial distribution</p><ul><li>Each trial is independent.</li><li>There are only two possible outcomes in a trial- either a success or a failure.</li><li>A total number of n identical trials are conducted.</li><li>The probability of success and failure is same for all trials. (Trials are identical.)</li></ul><h3>Log Normal Distribution</h3><p>a log-normal (or lognormal) distribution is a continuous probability distribution of a random variable whose logarithm is normally distributed. Thus, if the random variable X is log-normally distributed, then Y = ln(X) has a normal distribution. Likewise, if Y has a normal distribution, then the exponential function of Y, X = exp(Y), has a log-normal distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*f2XJ817-elfGBbh9m5kfwQ.jpeg" /></figure><h4>Applications</h4><ul><li>The length of comments posted in Internet discussion forums follows a log-normal distribution.</li><li>In economics, there is evidence that the income of 97%–99% of the population is distributed log-normally.</li></ul><h3>Power law distribution</h3><p>In statistics, a power law is a functional relationship between two quantities, where a relative change in one quantity results in a proportional relative change in the other quantity, independent of the initial size of those quantities: one quantity varies as a power of another.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*_X6qEDIvG4n1aJLg5BiDxQ.png" /></figure><p>Applications</p><ul><li>Distribution of income,</li><li>Magnitude of earthquakes,</li><li>Size of cities according to population,</li><li>Size of corporations,</li><li>Trading volumes on the stock market,</li><li>word frequencies.</li></ul><h3>BoxCox Transform</h3><p>A Box Cox transformation is a way to transform non-normal dependent variables into a normal shape.When you are dealing with real-world data, you are going to deal with features that are heavily skewed. Transformation technique is useful to stabilize variance, make the data more normal distribution-like, improve the validity of measures of association.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z_H5jYxhrK-lYMqVh6vqxQ.jpeg" /></figure><p>Till now we see various distributions.</p><p>In next article we will see co-variance and hypothesis testing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*VqVV4ReDVXTbhGp_z0rS8g.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a69c088ed7c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploratory Data Analysis]]></title>
            <link>https://medium.com/@peruljain/exploratory-data-analysis-f900d4841196?source=rss-4400006f232------2</link>
            <guid isPermaLink="false">https://medium.com/p/f900d4841196</guid>
            <dc:creator><![CDATA[Perul Jain]]></dc:creator>
            <pubDate>Tue, 01 Oct 2019 03:27:53 GMT</pubDate>
            <atom:updated>2019-10-01T03:27:53.474Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part-1</h3><p>Why Exploratory Data Analysis is important or why should we learn it?</p><p>Suppose you have a Iris dataset(https://www.kaggle.com/arshid/iris-flower-dataset). In this Dataset there are 4 fields or features like petal length , petal width, sepal length,sepal width and one result field which is type of flower(setosa,versicolor,verginica).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*z84WJPA8JvJrhFojMWkcgQ.jpeg" /></figure><p>Now you want to predict which type of flower when we have this given 4 features. Now the Exploratory data analysis come into picture.You explore data and collect information through this data.</p><p>Now let`s go through some code snippets so that you have more idea that how we do data analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4JoXniqiJwgqt3rYu9SCHQ.jpeg" /></figure><p>Now we load the data into dataframe by using pandas library.</p><p>Next step is to plot the data by using seaborn library.Below is the code snippet of how to plot given data in 2d scatter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*q1SwK7PfEqf4bMTYczvahQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*MKOCZOMA92IwVGYinx43iw.jpeg" /></figure><h3>Conclusions from above image</h3><p>1. Using sepal_length and sepal_width features, we can distinguish Setosa flowers from others.<br>2. Seperating Versicolor from Viginica is much harder as they have considerable overlap.</p><p>You think why we can”t use 3d plot,4d plot ,5d plot etc?</p><p>Because we are humans , we are only capable of seeing 3d plot .</p><h4>Pair plot</h4><p>This is useful when number of features is less . Because It plot pairs of features and if there are so many features then there are so many plots which is not feasible to visualize.</p><p>Now let’s go through code snippet and plot</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JLa7AWQlX5_86x3fsd7ldw.jpeg" /></figure><p>Conclusions from above Plot</p><p>1. petal_length and petal_width are the most useful features to identify various flower types.<br>2. While Setosa can be easily identified (linearly seperable), Virnica and Versicolor have some overlap (almost linearly<br>seperable).<br>3. We can find &quot;lines&quot; and &quot;if-else&quot; conditions to build a simple model to classify the flower types.</p><h3>Histogram,pdf,cdf</h3><p>Histogram</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*HlaJsVR-il2WkULO3tS0Bw.png" /></figure><p>A histogram is an accurate representation of the distribution of numerical data.</p><h4>Pdf(probability density function)</h4><p>a function of a continuous random variable, whose integral across an interval gives the probability that the value of the variable lies within the same interval.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*vURQ0OiUfx-0RsEcWWDjJA.jpeg" /></figure><p>Red color curve is probability density function.</p><h4>Cdf(cumulative density function)</h4><p>The area under the curve of a PDF(x) between -∞ and x equals its CDF(x).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*d7gi1M6CWNlpNHi5T7QoJg.jpeg" /></figure><p>Now we have little bit idea of histogram,pdf and cdf.</p><p>Let’s go through code snippet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QqwD5MFJMydvSLPz1zJR9Q.jpeg" /></figure><h4>Conclusions from above plot</h4><p>1.Setosa has petal length between 1cm and 2cm.</p><p>2.versicolor has petal length between 3cm and 5cm.</p><p>3.virginica has petal length between 5cm and 6.8cm.</p><p>4 There is overlapping of versicolor and virginica of probability density function which shows some error almost five percent.</p><p>Let’s go through to code snippet and plot pdf and cdf</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nUl9TWrJ5AuaIlh12p2MFA.jpeg" /></figure><p>YELLOW-&gt;CDF</p><p>BLUE-&gt;PDF</p><p>What we conclude from above cdf and pdf?</p><ul><li>81 percent of setosa flowers has less than 1.6 cm petal length.</li></ul><p>Let,s understand some terms which might be you are not familiar.</p><p>What is bin_edges ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*KIzF9Z4nM_0EhQeifJAiCw.jpeg" /></figure><p>What is count?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*y5EUOFBDSCBxFEqpYIJgLA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*2VfBoV8WcpHhjaLG7omCEg.jpeg" /></figure><p>Till now we see plot analysis,now let’s see some mathematical analysis.</p><h3>Statistics Analysis</h3><h4>Mean , variance,standard deviation</h4><p>Mean:</p><p>The statistical mean refers to the mean or average that is used to derive the central tendency of the data in question.</p><p>Variance:</p><p>In probability theory and statistics, variance is the expectation of the squared deviation of a random variable from its mean. Informally, it measures how far a set of (random) numbers are spread out from their average value.</p><p>Standard deviation:</p><p>A quantity expressing by how much the members of a group differ from the mean value for the group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*k_MlnxoFvKgVa0vYGCGyPw.png" /></figure><p>Now we have idea of mean,standard deviation and variance.</p><p>Let’s have a look that how this mathematical concepts helps in data analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y4ABEDpJNb4qa0j75VnFpg.jpeg" /></figure><p>Conclusion</p><ul><li>Mean + SD and Mean — SD gives range of particular flower sepal length and from this range we can easily classify flowers by simple if else condition without plotting the graph.</li></ul><h4>Disadvantages of mean and SD for Exploratory data analysis.</h4><ul><li>Suppose sepal length has min value is 1 and max value is 2 but if any how our data set contain 150 as a sepal length then this leads to data corrupt.</li><li>When there is an outlier ,it will give wrong results.</li><li>Mean is very sensitive to an outlier ,thus for an outlier dataset we avoid mean calculation.</li></ul><h3>HOW TO OVERCOME AN OUTLIER?</h3><h4>By using Median</h4><p>Median:</p><p>The median is a simple measure of central tendency. To find the median, we arrange the observations in order from smallest to largest value. If there is an odd number of observations, the median is the middle value. If there is an even number of observations, the median is the average of the two middle values.</p><h4>Why median?</h4><p>The mean may not be a fair representation of the data, because the average is easily influenced by outliers (very small or large values in the data set that are not typical). The median is another way to measure the center of a numerical data set. A statisticalmedian is much like the median of an interstate highway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*t_E1wtrTik-L8QXmBSFRPg.png" /></figure><ul><li>Quartiles tell us about the spread of a data set by breaking the data set into quarters, just like the median breaks it in half.</li><li>Quartiles are especially useful when you’re working with data that isn’t symmetrically distributed, or a data set that has outliers.</li><li>These are special cases of “percentiles.” A percentile tells you what number is higher than a certain percent of the rest of the dataset. For example, the “90th percentile” means the number that is higher than 90% of the other numbers in the group.</li></ul><ol><li>Minimum, or (rarely) “0th percentile”—the smallest number in the group.</li><li>1st quartile, Q1, or 25th percentile—the number that separates the lowest 25% of the group from the highest 75% of the group.</li><li>Median, or 50th percentile—the number in the middle of the group, when arranged from smallest to largest.</li><li>3rd quartile, Q3, or 75th percentile—the number that separates the lowest 75% of the group from the highest 25% of the group.</li><li>Maximum, or (rarely) “100th percentile”—the largest number in the group.</li></ol><p>Finally, one other related statistic is the interquartile range, or IQR: it’s the distance between the first quartile and the third quartile. The IQR is useful in calculating outliers. Any data value that is more than 1.5 times the IQR away from that central 50% group is called an outlier.<br>So, to check for outliers, you need to do two calculations:</p><p>Lower boundary is Q1 – 1.5 * IQR</p><p>Upper boundary is Q3 + 1.5 * IQR</p><h3>Plots</h3><h4>Box plot and Whiskers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*iFR_JgvAqwiGlRfAxoM8RQ.jpeg" /></figure><p>A Box and Whisker Plot (or Box Plot) is a convenient way of visually displaying the data distribution through their quartiles.</p><p>Here are the types of observations one can make from viewing a Box Plot:</p><ul><li>What the key values are, such as: the average, median 25th percentile etc.</li><li>If there are any outliers and what their values are.</li><li>Is the data symmetrical.<br>How tightly is the data grouped.</li><li>If the data is skewed and if so, in what direction.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*JJSEEZ6cWNHJiYkb-y7lKg.png" /></figure><h4>Violin plots</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*buItnAVQtX9fdlpqoT1Fdg.jpeg" /></figure><p>A Violin Plot is used to visualise the distribution of the data and its probability density.</p><p>Box Plots are limited in their display of the data, as their visual simplicity tends to hide significant details about how values in the data are distributed. For example, with Box Plots, you can’t see if the distribution is bimodal or multimodal. While Violin Plots display more information, they can be noisier than a Box Plot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*qPZQaYoPy_RVkPt-0J-vzA.png" /></figure><h3>Conclusions</h3><ul><li>Write your observations clearly because for data scientist or machine learning engineer .It is very important to show their observation to non-techical person who understands easily by seeing the observation.</li></ul><p>References</p><ul><li>Violin plot - Wikipedia</li><li>https://en.m.wikipedia.org › wiki<br>Box plot - Wikipedia</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f900d4841196" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python vs R for Data Science]]></title>
            <link>https://medium.com/@peruljain/python-vs-r-for-data-science-11e1a4add557?source=rss-4400006f232------2</link>
            <guid isPermaLink="false">https://medium.com/p/11e1a4add557</guid>
            <dc:creator><![CDATA[Perul Jain]]></dc:creator>
            <pubDate>Thu, 26 Sep 2019 05:02:18 GMT</pubDate>
            <atom:updated>2019-09-26T05:02:18.229Z</atom:updated>
            <content:encoded><![CDATA[<p>Python and R are both open-source programming languages with a large community. New libraries or tools are added continuously to their respective catalog. R is mainly used for statistical analysis while Python provides a more general approach to data science.</p><h3>R</h3><p>Academics and statisticians have developed R over two decades. R has now one of the richest ecosystems to perform data analysis. There are around 12000 packages available in CRAN (open-source repository). It is possible to find a library for whatever the analysis you want to perform. The rich variety of library makes R the first choice for statistical analysis, especially for specialized analytical work.</p><h3>Python</h3><p>Python can pretty much do the same tasks as R: data wrangling, engineering, feature selection web scrapping, app and so on. Python is a tool to deploy and implement machine learning at a large-scale. Python codes are easier to maintain and more robust than R. Years ago; Python didn’t have many data analysis and machine learning libraries. Recently, Python is catching up and provides cutting-edge API for machine learning or Artificial Intelligence. Most of the data science job can be done with five Python libraries: Numpy, Pandas, Scipy, Scikit-learn and Seaborn.</p><h3>Percentage of people switching</h3><p>Ps: python people are more loyal than R people ):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*r5OPzpTgNLqCOwUyGTU7ag.jpeg" /></figure><h3>Job opportunity and salaries</h3><p>The picture below shows the number of jobs related to data science by programming languages. SQL is far ahead, followed by Python and Java. R ranks 5th. If we focus on the long-term trend between Python (in orange) and R (blue), we can see that Python is more often quoted in job description than R.<br>In terms of salaries, in 2017, the average annual salaries were $99,000 (R) and $100,000 (Python).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*BB6T4V_Hu5MPBGAbifMvxA.png" /></figure><h4>Conclusion : Is Python a Good Language for Your Next Project</h4><p>Python is definitely a language worth considering for your next project. Python is chosen by the best in the world, companies like Google, Facebook or Microsoft, and it’s growing very fast. Developers love its features. Python is simple, approachable, versatile and complete. This language is an obvious choice for machine learning, data analysis and visualisation. AI-first companies should love it. Just like any programming language.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11e1a4add557" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>